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 write to program memory or program memory erase is executed on blocks of n bytes at a time. Refer to the memory organization table for write and erase block sizes. A Bulk Erase operation cannot be issued from user code.

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 rows. A row is the minimum size that can be erased by user software. Refer to the memory organization table for the row sizes for the these devices.

After a row has been erased, all or a portion of this row can be programmed. Data to be written into the program memory row is written to 8-bit wide data write latches which are also referred to as holding registers. These latches are not directly accessible, but may be loaded via sequential writes to the TABLAT register.

Important: To modify only a portion of a previously programmed row the contents of the entire row must be read and saved in RAM prior to the erase. Then, the new data and retained data can be written into the write latches to reprogram the row of PFM. However, any unprogrammed locations can be written without first erasing the row. In this case, it is not necessary to save and rewrite the other previously programmed locations.
Table 12-2. Flash Memory Organization by Device
DeviceRow Erase Size (Words)Write Latches (Bytes)TBLPTR LSbs (Latch Address)Program Flash Memory (Words)EEPROM Data Memory (Bytes)
PIC18(L)F45K403264616384256
PIC18(L)F26K40327681024
PIC18(L)F46K40