when to switch between banks

Discussion in 'Embedded Systems and Microcontrollers' started by ecka333, Jun 17, 2010.

  1. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    Hello, i am using pic16h876a microcontroller. I know, that i must switch to the corresponding bank, when i want to change particular's register's bit with btf, bcf instructions. But if i only want to check bits with btfsc, btfss instructions, must i to switch to corresponding bank (where this bit is) or not?
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    You always have to be in correct bank for any register operation. I often use the banksel directive. As the code will be more portable to other PICs.
    Code ( (Unknown Language)):
    2.  banksel TRISB           ;Since this register is in bank 1,
    3.                           ;not default bank 0, banksel is  
    4.                           ;used to ensure bank bits are correct.
    5.   clrf    TRISB           ;Clear TRISB. Sets PORTB to outputs.
    6.   banksel PORTB           ;banksel used to return to bank 0,
    7.                           ;where PORTB is located.
    8.   movlw   0x55            ;Set PORTB value.
    9.   movwf   PORTB
    10.   goto    $
    11.   end                     ;All programs must have an end.