PICkit™ 3 Starter Kit User’s Guide
DS41628B-page 90 2012 Microchip Technology Inc.
EXAMPLE 3-49:
This code reads a single byte in program memory. Only the lower eight bits are used.
First, the high address of the table is loaded into EEADRH. The lower address is not
assigned immediately, but rather after adding the offset (ADC result) into the address
first. This is to ensure that the added offset to the low address will not cause an unde-
tected overflow (255->0).
3.13.7.2 PIC18
The PIC18 supports two methods to access constants in program memory:
1. Computed GOTO
2. Table Reads
The code will implement two different ways to utilize these methods:
1. Computed GOTO
• Program Counter
2. Table Reads
•
tblrd instruction
The PIC18 can also use the EECON/EEDAT/EEADR SFRs for table reads. Please see
the enhanced core implementation in assembly for more information.
In order to read and write program memory, there are two operations that allow the
processor to move bytes between the program memory space and the data RAM:
• Table Read (
tblrd)
•Table Write (
tblwt)
This lesson will only perform table reads and hence use the
tblrd instruction.
The program memory space is 16 bits wide, while the data RAM space is 8 bits wide.
Table reads and table writes move data between these two memory spaces through an
8-bit register (TABLAT).
The table read operation retrieves one byte of data directly from program memory and
places it into the TABLAT register.
banksel EEADRL ; bank 3
movlw high TableStart ;
movwf EEADRH ; Store MSb of address
movlw low TableStart ;
addwf temp, w
btfsc STATUS, C
incf EEADRH, f
movwf EEADRL ; Store LSb of address
bcf EECON1, CFGS ; Do not select Configuration Space
bsf EECON1, EEPGD ; Select Program Memory
bcf INTCON, GIE ; Disable interrupts
bsf EECON1, RD ; Initiate read
nop ; Executed
nop ; Ignored
bsf INTCON, GIE ; Restore interrupts
movf EEDATL, w ; Get LSb of word
return
;movwf PROG_DATA_LO ; Store in user location
;movf EEDATH,W ; Get MSb of word
;movwf PROG_DATA_HI ; Store in user location