MPLAB IDE Bank Errors

Discussion in 'Programmer's Corner' started by Retiredguy, Feb 25, 2015.

  1. Retiredguy

    Thread Starter Member

    Feb 24, 2007
    Hi guys,
    I am using MPLAB IDE v8.66 and am having problems with the banksel and pagesel command when I am building the asm files. It has been a few years since I have played with this stuff . When I do a build, I get a bunch of wrong bank errors. When I do a banksel command it seems to always stay in bank 0. I just wonder if I have something wrong in the settings of the program since this is a new install on a newer computer. Any help would be great.

    Last edited: Feb 25, 2015
  2. JohnInTX


    Jun 26, 2012
    BANKSEL will work if you specify the address of the RAM variables as full 12-bit values i.e. a variable in bank 1 at offset 20h should be declared as
    Code (Text):
    1. aRAMvar equ 120h
    2. .. blah blah
    3. BANKSEL aRAMvar ; generates code to select RAM bank 1
    4. movf aRAMvar,W; moves the byte at 120h to W
    6. BANKSEL 1 ; this selects RAM bank 0!  The argument to BANKSEL is 0 01h, not 1 00h
    7. movf aRAMvar,W; moves the byte at 020h from bank 0, not 120h
    Old code did not have/use BANKSEL so frequently only specified the 8LSBs since the bank selection had to be done manually. RAM addresses could be specified as just the offset i.e. 20h for the 4 separate locations 020h,120h,220h,320h - and since the instructions only encode the lower 8 bits it didn't matter. However, BANKSEL will take the upper address as 0 for all of these.

    If you specify BANKSEL as a literal, be sure to specify 100h for bank 1, 200h for bank 2 etc. for the same reason.
    You can suppress warning 302 (Register operand not in bank 0. Ensure that bank bits are correct.) its pretty worthless since it flags every operand not in bank 0. Just use BANKSEL to make sure you are in the right RAM bank.

    PAGESEL is similar but for program ROM. It generates instructions that set up PCLATH before jumps, etc. Like BANKSEL, PAGESEL requires the full address associated with the label. PAGESEL has no effect on program flow until you goto or call.
    Warning 306 is like 302 but for ROM. Its a little more useful but still annoying as it flags perfectly valid gotos and calls.

    I use custom macros, Fcall and Fgoto that suppress warning 306. They compare the target ROM bank with the current bank and flip PCLATH bits directly then do the call or goto. Warning 306 is re-enabled at the end of the macro. This way, I know I am crossing banks (by using Fcall/Fgoto) AND I still get warning 306 if I goof up and use a normal call/goto to cross banks. Nice.

    If you are just getting back into PICs, why not look at the 18F or enhanced midrange? They get rid of lots of the banking/paging headaches.
    Last edited: Feb 25, 2015
    absf likes this.
  3. Retiredguy

    Thread Starter Member

    Feb 24, 2007
    Thanks John
    Got it built now( it is amazing just how much a capital O and zero look so much alike)
    thanks again