Memory Banks and File Addresses

Discussion in 'Programmer's Corner' started by ke5nnt, Oct 5, 2009.

  1. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    When setting Equates I have noticed something in examples I've seen.

    In an example, the programmer wrote:

    PORTA equ 05
    TRISA equ 05
    PORTB equ 06
    TRISB equ 06

    Yet, in the datasheet for the referenced PIC, it says porta address is 05h while trisa address is 85h, same for portb and trisb (06h and 86h respectively). Can someone explain this to me? Wouldn't specifying trisa and b as 0x instead of 8x cause a problem?
     
  2. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Use the include file.
     
  3. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    So if I use the include file, I don't need to use equates at all?
     
  4. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    It pretty much is the equates for the specific PIC and much more. It's a text file so you can see what it does just open it with notepad.

    Some registers are duplicated in more than one bank, a few are in all four.

    bankswitching is only there because this part is based on the 1650 from the 1970's. Memory was very expensive then. The advanced series 18F PICs have much better memory management and a superior instruction set.
     
  5. ke5nnt

    Thread Starter Active Member

    Mar 1, 2009
    384
    15
    Thank you blueroom. I truly hope you and everyone else here at AAC who answers seemingly simple questions realize how big a help you are all being. The learning process would be so much more difficult without your contributions.
     
  6. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    Yes, blueroomelectronics is right. If you use include file, you need not to declare SFRs by equating. But as a new user, I will advice you to declare SFRs by yourself instead of include file as by that way you will keep yourself apprised with the Banks and address and other important information which are very much useful for pic16F series. At least for first 15 programs you write.

    In the datasheet if it is written that PORTB = 0x06 (means 06H) and
    TRISB = 0x86, then you should equate as follows:

    PORTB = 0x06 or 06H
    TRISB = 0x86 or 86H

    This means, PORTB is in Bank0 and TRISB is in Bank1. And whenever you want to do anything with TRISB or any other SFRs in Bank1, You have to go to Bank1 by writing BSF STATUS,5 , act with that SFR and then has to fall back to Bank0 by writing BCF STATUS,5 and carry out other codes or the program will show error.

    Keep it in mind, all the codes are written by seating in Bank0 but whenever you deal with any other SFR located not in BANK0, you have to go that Bank, do the job and has to fall back to Bank0.

    Small point,but very important for PIC16F Series. IN Assembly Language, small points matter much.
    Thanks.
     
    Last edited: Oct 5, 2009
Loading...