Page 1 of 1

Access Bank Clarification

PostPosted: Wed Jul 25, 2018 3:00 pm
by lionkingleo
Having spent some considerable time trying to understand the Bank selecting strategy employed in a PIC18F 4520 CPU, I still find it very confusing and would appreciate a clear explanation. From the data sheets, the access bank comprises 256 bytes of data Ram encompassing an address range of 00 - FF. Within that range, Addresses 00 - 7F comprise general purpose registers (GPR's) while addresses 80 - FF encompass the special function registers To modify data in the access bank requires you only to set the suffix 'a' in the instruction to 0. My confusion is over the fact that the SFR registers such as PORTA - PORTE are also listed as being in Bank 15. To access the PORTA register for example, do I have to explicitly set the BSR to 15 and set the suffix 'a' in the instruction to 1? or can I simply access PORT A using the suffix 'a' in the instruction set to 0? The movwf instruction states that if 'a' = 1, the bank select register is used to select the GPR bank (default) so presumably the BSR must be set to 15 prior to using the movwf instruction as follows:
movlb .15 ; select bank 15
movlw 0x0F
movwf PORTA,1 ; update PORT data

or is this better?

movlb .0 ; clear BSR
movlw 0x0F
movwf PORTA,0 ; force use of access bank

Any feedback would be appreciated ...suffered a minor stroke back in January, so I find that I need clarity of understanding before digging a deep hole for myself.

Thank you!!

Re: Access Bank Clarification

PostPosted: Wed Jul 25, 2018 3:28 pm
by vloki
Whith the RAM access bit in the instruction you select whether the BSR is used for addressing or not.

-> if you use access mode (without BSR) it makes no sense to configure BSR at all.

If the BSR is not used only the access bank is available, which is composed from lower part of bank 0 and higher part of bank 15 which holds all SFRs.
See figure 5-6 Data Memory Map...

Re: Access Bank Clarification

PostPosted: Thu Jul 26, 2018 2:18 am
by ric
lionkingleo wrote: Within that range, Addresses 00 - 7F comprise general purpose registers (GPR's) while addresses 80 - FF encompass the special function registers

The actual division depends upon which specific PIC18F device you are using. Not all of them switch from one to the other at 0x80.
e.g. in a PIC18F24K42, the division is at 0x60.
So, 0x00 to 0x5F accesses GPRs (the first 96 bytes of bank 0) and 0x60 to 0xFF accesses SFRs (the last 160 addresses in bank 15)

The whole point of the Access Bank is it lets you access those register WITHOUT touching the bank select register.

Re: Access Bank Clarification

PostPosted: Thu Jul 26, 2018 4:27 pm
by lionkingleo
Thanks to all who submitted replies .... Nice to get some independent confirmation

Thank you !!