Question on memory access between banks -- PIC

Discussion in 'Embedded Systems and Microcontrollers' started by wannaBinventor, Nov 25, 2010.

  1. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    I'm curious about something on the memory organization of a PIC. We will use the 16F819 as an example.

    Data sheet below:
    http://ww1.microchip.com/downloads/en/devicedoc/39598e.pdf

    Alright, there are general purpose registers in three different banks: Bank 0, bank 1, and bank 3.

    Bank 0 has locations 20h through 7Fh, bank 1 has A0h through EFh, and bank 2 has 120h through 16Fh.

    Say I were to need to move a value from general purpose memory location in bank 2 (Say location 121h) to the SSPBUF in bank 0.

    Is it as simple as turning to bank 2, then using "MOVF 121h,w" --- turning back to bank 0, and then moving the value from w into the SSPBUF.

    Are values in the W register always preserved when switching between banks?

    Thanks.
     
  2. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    W and a handful of SFRs are in all banks. You can switch banks without affecting them.

    PS you might want to skip the 16F series and try the 18F instead. Much easier to work with.
     
  3. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    W is "global"

    For the 16F series, I suggest using BoostC or other C compiler rather than assembly, especially if just getting started.
     
  4. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    What's with the constant adverts for SourceBoostC?
    Have you got shares in the company or something?

    I will admit its quite a reasonable compiler but it's by no means the be-all and end-all of C compilers. It has its share of weaknesses and short-comings as do most other compilers out in the market place. In any case if you are competent in C programming it should make very little difference which compiler you use.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718

    No, I don't work for them. I just find their examples that are included to be extremely useful for people new to programming. Microchip needs to include a bit more for samples, so does Hi -Tech. mikroC is decent, and I link to them now and again as well.

    Most people that ask questions about microcontrollers are completely new to the concept, and for the price, sourceboost can't be beat, especially with the low cost upgrades for plugins. It is an order of magnitude less expensive for the full version compared to the full version of other compilers. I also find it easier to help somebody that is using the compiler specific includes. Different PIC C compilers use different header files, and I can't really afford the full versions of all compilers simply to help answer questions.
     
  6. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    I'm a fan of BoostC too but why push it constantly, especially when it has absolutely nothing to do with the original question...
     
Loading...