PIC microcontrollers have two memory blocks, program memory and data memory. Like a harvard architecture, each block has its own bus so access to each can occur on the same oscillator cycle.
The data memory are further broken down in Special Function Registers (SFRs) and General Purpose RAM. The SFRs control the core of the microcontroller and its functions are readily available in the mcu’s datasheet. Taking PIC16F877a as an example, below is a snapshot of the table of its SFRs:
Here is the datasheet if you want to check it out.
PIC Microcontroller’s Program Memory Organization
The program memory block is the location where the user’s program is saved and it is nonvolatile, storing the information even if the power is turned off. This usually has the largest memory size in mcu.
A PIC mcu also has a program counter (PC) which is capable of addressing its program memory. It keeps track of the executed instructions by storing the address of the current instruction being processed. After the process is complete, the address stored in the PCs get incremented and the instruction in the new address gets executed.
PIC Microcontroller’s Data Memory Organization
The PIC microcontroller’s data memory, partitioned into multiple banks, is composed of the Special Function Registers (SFRs) and the General Purpose Registers (GPRs). The SFRs control the operation of the microcontroller while the GPRs acts as data storage. The number of available banks in the data memory depends on the microcontroller.
Each of the bank’s lower locations are reserved for the Special Functions registers and above it are General Purpose Registers. The default bank of mcu’s with multiple bank is BANK0. To access registers that are location on a different bank you need to set a special register to do so, such as STATUS register.
There is no need to study all the SFRs of a microcontroller in order to begin programming. You only need to familiarize yourself with a few important registers:
- STATUS Register – transitions between banks
- PORT Register – assigns or reads signals to and from the ports
- TRIS Register – sets the data direction of ports
Have fun programming!