12.1 Program Flash Memory

The Program Flash Memory is readable, writable, and erasable during normal operation over the entire VDD range.

A read from program memory is executed one byte at a time. A program memory erase is executed on blocks of n bytes at a time, also referred to as sectors. Refer to the following table for write and erase block sizes. A Bulk Erase operation cannot be issued from user code. A write to program memory can be executed by sectors or single words.

Table 12-2. Flash Memory Organization by Device
Device Sector Erase Size (Words) Holding Registers (Bytes) TBLPTR LSbs (Holding Address) Program Flash Memory (Words) Data Flash Memory (Bytes)
PIC18F27Q10 128 256 8 65536 1024
PIC18F47Q10

Writing or erasing program memory will cease instruction fetches until the operation is complete. The program memory cannot be accessed during the write or erase, therefore, code cannot execute. An internal programming timer terminates program memory writes and erases.

A value written to program memory does not need to be a valid instruction. Executing a program memory location that forms an invalid instruction results in a NOP.

It is important to understand the PFM memory structure for erase and programming operations. Program memory word size is 16 bits wide. PFM is arranged in sectors. A sector is the minimum size that can be erased by user software.

After a sector has been erased, all or a portion of this sector can be programmed. Data can be written directly into PFM one 16-bit word at a time using the NVMADR and NVMCON1 controls or as a full sector from sector RAM, which is also referred to as the holding registers. These 8-bit registers are located in the RAM bank following the last GPR RAM bank. The holding registers are directly accessible as any other SFR/GPR register and also may be loaded via sequential writes using the TABLAT and TBLPTR12.5.7 TBLPTR registers.

Important: To modify only a portion of a previously programmed sector the contents of the entire sector must be read and saved in RAM prior to the sector erase. The SECRD operation is the easiest way to do this. Then, the new data can be written into the holding registers to reprogram the sector of PFM. However, any unprogrammed locations can be written using the single word write operation without first erasing the sector.