when to switch between banks

Thread Starter

ecka333

Joined Oct 1, 2009
76
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?
 

t06afre

Joined May 11, 2009
5,934
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.
Example
Rich (BB code):
 banksel TRISB           ;Since this register is in bank 1, 
                          ;not default bank 0, banksel is  
                          ;used to ensure bank bits are correct. 
  clrf    TRISB           ;Clear TRISB. Sets PORTB to outputs. 
  banksel PORTB           ;banksel used to return to bank 0, 
                          ;where PORTB is located. 
  movlw   0x55            ;Set PORTB value. 
  movwf   PORTB 
  goto    $ 
  end                     ;All programs must have an end.
 
Top