Enhanced Mid-Range PIC® MCU Program Memory

Program memory on the Enhanced Mid-Range PIC® MCU consists of up to 32 MB of 14-bit wide Flash memory. After the MCU is programmed, the program memory contains the user's application code. Program memory is accessed by a 15-bit Program Counter (PC) register.

pm-layout.png
pm-vectors.png

RESET Vector

At RESET, the program counter is cleared, resulting in all zeros. This allows program memoryaddress 0h to be the location of the first instruction executed after a RESET condition.

Interrupt Vector

When an interrupt occurs, program control is transferred to address 04h. The"Interrupts" section provides a complete description of the interrupt process

return-stack.png

Return Stack

A 16-entry, 15-bit wide hardware return stack stores the PC in the event of either an interrupt or call to a subroutine. The return stack works on a last-in-first-out basis.
Upon executing a RETURN instruction, (RETFIE orRETURN), the top element of the stack is removed from the stack and placed into the program counter.

In order to read or modify the 14-bit PC with an 8-bit MCU, two Special Function Registers (SFRs) are utilized:

  • PCL - contains the lower 8 bits of the program counter <PC7:0>
  • PCLATH - content depends upon MCU operation being performed


PCL andPCLATH are used when the program writes to the PC, reads the program counter, or executes aGOTO orCALL instruction.

Writing to the PC

When the application writes toPCL, the current contents ofPCLATH<5:0> will be written toPC<14:8>. Because of this, the contents ofPCLATH<5:0> MUST always be correct BEFORE writing toPCL.

pcl-write.png

Reading the PC

WhenPCL is read by an application,PC<14:8> is captured intoPCLATH.

pcl-read.png

Executing a CALL or GOTO instruction

TheCALL andGOTO instructions only have 11 bits available to specify the destination address.PCLATH is used to extend the operand to access all the program memory addresses. When either aCALL orGOTO is executed, the 11-bit address from the operand is loaded intoPC<10:0> andPCLATH<6:3> is loaded intoPC<14:11>.

goto.png