The 16F84 PIC only has seven bits which it can use to express the address of a register (this is done to keep the PIC instructions short and so reduce memory requirements).

Note that the PORTA register lives at 0x05 (hex 5) and the PORTA data direction register (TRISA) lives at 0x85. There is exactly 0x80 difference between the two addresses. This difference is reflected in the state of 1 bit (if you look at the way that numbers work you will find that 0x80 is equal to just the eighth bit set high).

The PICmicro uses a bit in the STATUS register to hold the eighth bit. A program must set the state of this bit depending on which particular register to be accessed. On the right you can see how one of the bits in the status register is combined with the address obtained from the instruction to get a nine bit address for a given register.

We set the bank we want to access by setting or clearing bit 5 of register 0x03 (the STATUS register). If this bit is set it equates to the eighth bit of the register addresses being pulled high (i.e. we add 0x80 to all the register addresses and access registers in what is called bank 1). If this bit is clear we do not add 0x80 and so we access registers in bank 0.

You can do this in C2C by using the functions set_bit and clear_bit:

    /* set bit 5 of register 3   */
    /* we are now using bank 1   */
    set_bit ( 3, 5 ) ;

    /* clear bit 5 of register 3 */
    /* we are now using bank 0   */
    clear_bit ( 3, 5 ) ;

To make life easier, the C2C compiler lets us use the names of the registers as given above, instead of 3 we can use the word STATUS. There is also a convention that RP0 means the bank select bit 0.(other PICmicros have more than two banks, and so need more than one back select bit).

This makes our code look like this:

    /* bank 1 */
    set_bit ( STATUS, RP0 ) ;
    /* bank 0 */
    clear_bit ( STATUS, RP0 ) ;

You should try to learn the names of each of these file registers and bits, and should avoid using the numeric values. This will make your programs clearer, and also make it easier to move the program onto another version of the PIC processor where the actual locations of the registers have changed, but the names remain the same.

The set_bit and clear_bit functions map directly onto assembler instructions which set and clear bits in particular file registers. You can use them to set and clear bits in your variables as well:

    /* set bit 7 of i */
    set_bit ( i, 7) ;