The internal block diagram iPIC16F87x in figure1 shows the three memory block the program memory, EEPROM data memory and the RAM; some controller like 16C61 has only two blocks of memory program memory and data memory. As shown the program memory and the data memory use separate buses for concurrent access of these memory. 16F877 has 8K x 14 bit word memory and 8 byte stack organization.
Figure-1 shows the program and the stack memory map organization. Whereas the program memory is used to store the application program, the stack memory is used only for storing return addresses and some critical data that is required to be saved while transferring the contol of the program such as call to subroutine etc.
The reset and the interrupt vector of this controller is 0000h and 0004h
figure-1 also shows stack. PIC has 8-level deep 13 bit wide hardware stack and is not part of any program or data memory. SP in PIC controller is neither writable nor readable. The operation of the stack is as follows:
During a CALL instruction or branch due to INTERRUPT, the PC is automatically pushed onto stack, and it is POPed in the event of execution of RETURN, RETLW or RETFIE instruction. On 8 subsequent PUSHED the SP rolls back and overwrites the 1st PUSH data and thus the stack acts as a circular buffer.
There is no separate POP or PUSH instruction in PIC for stack operation, it automatically happens during CALL, RETURN, RETLW and RETFIE instructions.
Program Memory Paging Concepts:
PIC 16F877 supports upto 8Kx14 bit program memory. The CALL and GOTO instructions provide 11-bit address so as to branch within 2K program memory page.
For a CALL and GOTO instructions, the upper two bits of the address are provided by PCLATH<4:3> .
The programmer has to ensure that the page select bits are programmed so that the desired program memory page is addressed. For a return from the CALL instruction however, the complete 13 bit address is POPed out into the PC
The data memory in PIC microcontroller is divided into a number of banks depending upon the PIC family and version(for example PIC 16F84 has two banks (15 SFR, 68 General purpose registers), PIC 16F877 has four banks, 74 SFRs rest 368 general purpose register as SRAM), each bank of 128 bytes in size. It is also called as register file and is divided in two types:
Special Function Registers (SFR)
General Purpose Registers (GPR)
The GPR is of 368 bytes implemented as SRAM. The data memory is shown in figure below: