A problem of bank selection 16F877A

Thread Starter

anhnha

Joined Apr 19, 2012
905
Hi everyone,
I am programming for pic 16F877A in PICC. The program is writen in assembly, There is a strange that make me confused:
In order to set all pins of port B are output , I used two command:
MOVLW 0x00 // assign W=0X00
MOVWF TRISB // set all bit of trisb to zero
but when I watch in list file after compilation, a feel confused when it is like that:
MOVLW 00 // assign W=0X00
BSF 03.5 // set RP0 bit to choose bank1 contain TRISB
MOVWF 06 // Move W to f
I think it have to MOVWF 86 because 86 is address of TRISB , 06 is address of PORTB.
But my program still work exactly.
Would you help me explain why it is happen like that?
Thanks.
 

ErnieM

Joined Apr 24, 2011
8,377
Hopefully by now you have found the data sheet for the 877A. If you look at "FIGURE 2-3: PIC16F876A/877A REGISTER FILE MAP" you can see the special function registers and memory registers are placed in 4 "banks."

Why? The entire memory address runs from 0x000 to 0x1FF, which takes 9 bits to hold. If you peek into "TABLE 15-2: PIC16F87XA INSTRUCTION SET" you can see the instructions only have place to hold 7 bits to specify a register.

So where do the other 2 bits come from? The "Register Bank Selection" bits of the Status register. See "2.2.2.1 Status Register" Also note in Fig 2-3 the Status register appears in all banks, so it is always accessible.

You could write your own code to set the bits as needed, or you can use the banksel [label] macro. That macro takes the register of [label] and makes the correct code to set the bank bits. Look for it in the MPASM Assembler Help file found under MPLAB's help menu.
 
Top