Bank selection in PIC18F65K22 and MPASM

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
treez
Posts: 161
Joined: Sat Dec 27, 2008 8:39 am

Bank selection in PIC18F65K22 and MPASM

Post by treez » Tue Oct 07, 2014 12:10 pm

Hello,
I am writing assembler for PIC18F65K22. Presumably if I want to use any SFR I just put "banksel LATA" for example, just before the code? (assuming that the next line refers to the LATA register)
It seems strange though because all the SFRs are in bank 15?
Also, do you know where the GPRs are..is it bank 0? -do you know what address's the GPRs are at?

User avatar
phalanx
Non-SFE Guru
Posts: 1992
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Bank selection in PIC18F65K22 and MPASM

Post by phalanx » Wed Oct 08, 2014 6:03 am

On the particular PIC you are using, GPR's reside from address 0x000 to 0x7FF. The most significant byte of the address is set using the bank select register (BSR). This means you can access 8 banks of memory (0-7) with 256 bytes each for a total of 2048 bytes of memory. SFR's reside in Bank 15 and occupy the space from 0xF16 to 0xFFF.

PIC18's have a feature called an "access bank" which maps a portion of the RAM in Bank 0 and a portion of the SFRs in Bank 15 to a special bank that can be directly accessed by the PIC regardless of your BSR setting. The mappings vary depending on the PIC but your particular one maps RAM from 0x000 to 0x05F and SFRs from 0xF60 to 0xFFF. This means that any variable you locate in Bank 0 up to offset 0x5F and all SFRs in Bank 15 from offset 0x60 to 0xFF can be accessed without making use of the BSR. The SFR's in Bank 15 from 0x16 to 0x5F are not part of the access bank which means you have to set the BSR accordingly in order to use them.

All these details can be found in the datasheet starting at page 94.

-Bill

Post Reply