Microchip Technology MCU PIC PIC18F87K22-I/PTRSL TQFP-80 MCP PIC18F87K22-I/PTRSL Data Sheet

Product codes
PIC18F87K22-I/PTRSL
Page of 550
 2009-2011 Microchip Technology Inc.
DS39960D-page 115
PIC18F87K22 FAMILY
7.3
Reading the Flash Program 
Memory
The  TBLRD  instruction  is  used  to  retrieve  data  from
program memory and places it into data RAM. Table
reads from program memory are performed, one byte
at a time.
TBLPTR points to a byte address in program space.
Executing  TBLRD places the byte pointed to into
TABLAT. In addition, the TBLPTR can be modified
automatically for the next table read operation.
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. 
shows the interface between the internal program
memory and the TABLAT.
FIGURE 7-4:
READS FROM FLASH PROGRAM MEMORY 
EXAMPLE 7-1:
READING A FLASH PROGRAM MEMORY WORD 
(Even Byte Address)
Program Memory
(Odd Byte Address)
TBLRD
TABLAT
TBLPTR = xxxxx1
FETCH
Instruction Register
 (IR)
Read Register
TBLPTR = xxxxx0
BCF
EECON1, CFGS
; point to Flash program memory
BSF
EECON1, EEPGD
; access Flash program memory
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
MOVF
TABLAT, W 
; get data
MOVF
WORD_ODD