Microchip Technology MA180025 Data Sheet

Page of 450
 2010 Microchip Technology Inc.
DS39933D-page 97
PIC18F87J90 FAMILY
7.5.2
FLASH PROGRAM MEMORY WRITE 
SEQUENCE (WORD 
PROGRAMMING).
The PIC18F87J90 family of devices has a feature that
allows programming a single word (two bytes). This
feature is enabled when the WPROG bit is set. If the
memory location is already erased, the following
sequence is required to enable this feature:
1.
Load the Table Pointer register with the address
of the data to be written
2.
Write the 2 bytes into the holding registers and
perform a table write
3.
Set WPROG to enable single-word write.
4.
Set WREN to enable write to memory.
5.
Disable interrupts.
6.
Write 55h to EECON2.
7.
Write 0AAh to EECON2.
8.
Set the WR bit. This will begin the write cycle.
9.
The CPU will stall for the duration of the write for
T
IW 
(see parameter D133A).
10. Re-enable interrupts.
EXAMPLE 7-4:
SINGLE-WORD WRITE TO FLASH PROGRAM MEMORY
MOVLW    CODE_ADDR_UPPER 
; Load TBLPTR with the base address
MOVWF    TBLPTRU
MOVLW    CODE_ADDR_HIGH
MOVWF    TBLPTRH
MOVLW    CODE_ADDR_LOW
MOVWF    TBLPTRL
MOVLW    DATA0
MOVWF    TABLAT
TBLWT*+
MOVLW    DATA1
MOVWF    TABLAT
TBLWT*
PROGRAM_MEMORY
BSF
EECON1, WPROG 
; enable single word write
BSF
EECON1, WREN 
; enable write to memory
BCF
INTCON, GIE 
; disable interrupts
MOVLW
55h
Required
MOVWF
EECON2
 
; write 55h
Sequence MOVLW
0AAh
MOVWF
EECON2
; write 0AAh
BSF
EECON1, WR 
; start program (CPU stall)
BSF
INTCON, GIE
; re-enable interrupts
BCF
EECON1, WPROG 
; disable single word write
BCF
EECON1, WREN 
; disable write to memory