Datasheet
2010-2013 Microchip Technology Inc. DS40001430E-page 159
PIC16(L)F720/721
18.0 FLASH PROGRAM MEMORY
SELF READ/SELF WRITE
CONTROL
The Flash Program Memory is readable and writable
during normal operation of the device. This memory is
not directly mapped in the register file space. Instead,
it is indirectly addressed through the Special Function
Registers. There are six SFRs used to read/write this
memory:
•PMCON1
•PMCON2
•PMDATL
•PMDATH
• PMADRL
• PMADRH
When interfacing the program memory block, the
PMDATL and PMDATH registers form a two byte word
which holds the 14-bit program data for reading, and
the PMADRL and PMADRH registers form a two byte
word which holds the 13-bit address of the program
Flash location being accessed. These devices have 2K
to 4K words of program memory with an address range
from 0000h to 0FFFh.
Devices without a full map of memory will shadow
accesses to unused blocks back to the implemented
memory.
18.1 Program Memory Read Operation
To read a program memory location, the user must
write two bytes of the address to the PMADRH and
PMADRL registers, then set control bit RD
(PMCON1<0>). Once the read control bit is set, the
Program Memory Read (PMR) controller uses the two
instruction cycles to read the data. This causes the two
instructions immediately following the ‘BSF PMCON1,
RD’ instruction to be ignored.
The data is available in the third cycle, following the set
of the RD bit, in the PMDATH and PMDATL registers.
PMDATL and PMDATH registers will hold this value
until another read is executed. See Example 18-1 and
Figure 18-1 for more information.
EXAMPLE 18-1: FLASH PROGRAM MEMORY READ
Note: Interrupts must be disabled during the
time from setting PMCON1<0> (RD) to
the third instruction thereafter.
* This code block will read 1 word of program
* memory at the memory address:
PROG_ADDR_HI: PROG_ADDR_LO
* data will be returned in the variables;
* PROG_DATA_HI, PROG_DATA_LO
BANKSEL PMADRL ; Select Bank 2
MOVLW PROG_ADDR_LO ;
MOVWF PMADRL ; Store LSB of address
MOVLW PROG_ADDR_HI ;
MOVWL PMADRH ; Store MSB of address
BANKSEL PMCON1 ; Select Bank 3
BCF INTCON,GIE ; Disable interrupts
BSF PMCON1,RD ; Initiate read
NOP ; Ignored (Figure 18-1)
NOP ; Ignored (Figure 18-1)
BSF INTCON,GIE ; Restore interrupts
BANKSEL PMDATL ; Select Bank 2
MOVF PMDATL,W ; Get LSB of word
MOVWF PROG_DATA_LO ; Store in user location
MOVF PMDATH,W ; Get MSB of word
MOVWF PROG_DATA_HI ; Store in user location