Reading the Program Flash Memory

The TBLRD instruction retrieves data from program memory at the location to which the TBLPTR register points and places it into the TABLAT SFR register. Table reads from program memory are performed one byte at a time. The instruction set includes incrementing the TBLPTR register automatically for the next table read operation.

The CPU operation is suspended during the read, and resumes operation immediately after. From the user point of view, the value in the TABLAT register is valid in the next instruction cycle.

The internal program memory is typically organized by words. The Least Significant bit of the address selects between the high and low bytes of the word. The following figure illustrates the interface between the internal program memory and the TABLAT register.

Figure 1. Reads from Program Flash Memory
Figure 2. Program Flash Memory Read Flowchart

Reading a Program Flash Memory Word

   MOVLW   CODE_ADDR_UPPER    ; Load TBLPTR with the base   
   MOVWF   TBLPTRU            ; address of the word
   MOVLW   CODE_ADDR_HIGH
   MOVWF   TBLPTRH
   MOVLW   CODE_ADDR_LOW
   MOVWF   TBLPTRL
READ_WORD:
   TBLRD*+                    ; read into TABLAT and increment
   MOVF    TABLAT, W          ; get data
   MOVWF   WORD_EVEN
   TBLRD*+                    ; read into TABLAT and increment
   MOVFW   TABLAT, W          ; get data
   MOVF    WORD_ODD