The Details
Links Mentioned
None

Links
Home
AWC

Microchip
PicList


Home
Introducing the PIC
Selecting a PIC
A Programmer
Hardware Tools
Software Tools
Downloading
Fixing the Blink
A Numeric Example
The Details
Special Registers
PIC Instructions


 

Now that you've examined some code, it's time to look at those pesky details. The PIC has a Harvard architecture -- that means it stores data in one set of memory locations (often called registers) and it stores program data in another set of memory locations. This is different from, say, a PC where data and program memory is pretty much the same.

The data memory organization of a APP-II (PIC16F873) is fairly simple. In general, there are 4 banks of 128 byte-sized registers. However, some registers appear in more than one bank. Also, many registers have special meanings to the processor (for example, one register controls the A/D converter). Some memory locations don't even contain memory!

From the programmer's point of view, the usable memory on this processor is from 0x20 - 0x7F (96 bytes) in both bank 0 and bank 1. So you have 192 bytes of storage. The memory in bank 0 also appears in bank 2 and the memory in bank 1 is duplicated in bank 3. Everything from location 0 to 0x20 in each bank either has some special purpose, or doesn't exist at all.

How do you select a bank? The key is the RP bits in the STATUS register. Luckily, the STATUS register is in all 4 banks, so you can use it to switch banks without losing your way. The STATUS register has two bits, RP0 and RP1, that pick the bank (just form a 2 bit number from RP1:RP0 and it tells you the bank number from 0 to 3).

So if you want to write to location 0x20 and you don't know the current state of the RP bits, you might write:

   bcf status,rp1  ; rp1=0
   bcf status,rp0  ; rp0=0
   movwf 0x20

Notice that the W register is "special" -- it isn't part of the normal register set and therefore isn't in any bank. In the old days, we'd call that an accumulator. It is just a working register that is always available.

If you wanted to use the same variable in bank 1, you'd write:

   bcf status,rp1  ; rp1=0
   bsf status,rp0  ; rp0=1
   movwf 0x20

Usually, you'll use a define or cblock to specify your variables. For example, you might write:

counter EQU 0x20
        movwf counter

We'll talk about cblock later.

Also, the standard include files from Microchip provide definitions for the standard registers below 0x20 (like STATUS at 0x03). You'll read more about them in the next frame.

Back Next