Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

PIC : do I need to keep switching mem banks for register access?

I am programming the PIC16F877 which has 4 memory banks each bank containing various registers. Each register has its own address.
e.g PORTA Register (bank0) is 05h and TRISA register (bank1)is 85h


Q. Each time I need to refer to a register do I have to switch banks using the status register RP0,1 bits and then address the register as its bank position
e.g.

TRISA EQU H'05' ;Addressed as its position not 85h as in include file

BSF STATUS,5 ;Select bank1
MOVLW b'101111' ;Perform some function on TRISA
MOVWF TRISA ;
BCF STATUS,5 ;Reselect bank1


OR can I get away with

TRISA EQU H'85' ;This is what appears in include file
MOVLW b'101111' ;Perform function on TRISA
MOVWF TRISA ;with no bank switching



The latter technique seems to me to be the best approach as the code is shorter and i can make use of the PIC include file. The problem is that I get the following message:

'302 Register in operand not in bank 0. Ensure that bank bits are correct.'



Thanks
Joe

Comments

  • joankyjoanky Member Posts: 6
    : I am programming the PIC16F877 which has 4 memory banks each bank containing various registers. Each register has its own address.
    : e.g PORTA Register (bank0) is 05h and TRISA register (bank1)is 85h
    :
    :
    : Q. Each time I need to refer to a register do I have to switch banks using the status register RP0,1 bits and then address the register as its bank position
    : e.g.
    :
    : TRISA EQU H'05' ;Addressed as its position not 85h as in include file
    :
    : BSF STATUS,5 ;Select bank1
    : MOVLW b'101111' ;Perform some function on TRISA
    : MOVWF TRISA ;
    : BCF STATUS,5 ;Reselect bank1
    :
    :
    : OR can I get away with
    :
    : TRISA EQU H'85' ;This is what appears in include file
    : MOVLW b'101111' ;Perform function on TRISA
    : MOVWF TRISA ;with no bank switching
    :
    :
    :
    : The latter technique seems to me to be the best approach as the code is shorter and i can make use of the PIC include file. The problem is that I get the following message:
    :
    : '302 Register in operand not in bank 0. Ensure that bank bits are correct.'
    :
    :
    :
    : Thanks
    : Joe
    :


    this message is only a warning,

    I found this in the net

    At the RAM file register of PIC16F84A, a bank method is adopted. For example,

    both memory addresses of TMR0 and OPTION_REG is 01.
    However,
    TMR0 is at bank 0 and
    OPTION_REG is at bank 1.

    In the definition file which is read by INCLUDE, it defines the address of OPTION_REG as being H'0081'. Bank information is written.

    The bank must be designated with RP0 bit of the STATUS register by the actual processing.

    In case of MPLAB,
    to prevent mistake in the bank processing, warning message "Message[302]" is shown in the processing of the register of bank 1.
    "Register in operand not in bank 0. Ensure that bank bits are correct."
    Even if specifying a bank normally, this message is shown. To make not display this message, there is a way of changing a definition file designation. That is, the message becomes not displayed when changing the address of OPTION_REG into H'0001'.
    Or,
    there is a way of stopping the display of 302 messages using the ERRORLEVEL directive to be using this time.


    hope this helps you. bye :-)

  • Dave DawsonDave Dawson Member Posts: 15
    : I am programming the PIC16F877 which has 4 memory banks each bank containing various registers. Each register has its own address.
    : e.g PORTA Register (bank0) is 05h and TRISA register (bank1)is 85h
    :
    :
    : Q. Each time I need to refer to a register do I have to switch banks using the status register RP0,1 bits and then address the register as its bank position
    : e.g.
    :
    : TRISA EQU H'05' ;Addressed as its position not 85h as in include file
    :
    : BSF STATUS,5 ;Select bank1
    : MOVLW b'101111' ;Perform some function on TRISA
    : MOVWF TRISA ;
    : BCF STATUS,5 ;Reselect bank1
    :
    :
    : OR can I get away with
    :
    : TRISA EQU H'85' ;This is what appears in include file
    : MOVLW b'101111' ;Perform function on TRISA
    : MOVWF TRISA ;with no bank switching
    :
    :
    :
    : The latter technique seems to me to be the best approach as the code is shorter and i can make use of the PIC include file. The problem is that I get the following message:
    :
    : '302 Register in operand not in bank 0. Ensure that bank bits are correct.'
    :
    :
    :
    : Thanks
    : Joe
    :
    Yes, you need to set the RP0 bit. But if you set it up in subroutine and just call the subroutine, it will reduce your coding. The 16F84 uses TRISA, TRISB & OPTION, but you are advised not to use them and when you build, you are warned not to use them, but you are forgiven anyway.

    Dave
Sign In or Register to comment.