English
Language : 

PIC18F44J50-I Datasheet, PDF (111/562 Pages) Microchip Technology – 28/44-Pin, Low-Power, High-Performance USB Microcontrollers
PIC18F46J50 FAMILY
7.5.2
FLASH PROGRAM MEMORY WRITE
SEQUENCE (WORD
PROGRAMMING)
The PIC18F46J50 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. (It must be an even
address.)
2. Write the 2 bytes into the holding registers by
performing table writes. (Do not post-increment
on the second table write.)
3. Set the WREN bit (EECON1<2>) to enable
writes and the WPROG bit (EECON1<5>) to
select Word Write mode.
4. Disable interrupts.
5. Write 0x55 to EECON2.
6. Write 0xAA to EECON2.
7. Set the WR bit; this will begin the write cycle.
8. The CPU will stall for the duration of the write for
TIW (see Parameter D133A).
9. Re-enable interrupts.
EXAMPLE 7-4:
SINGLE-WORD WRITE TO FLASH PROGRAM MEMORY
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
CODE_ADDR_UPPER
TBLPTRU
CODE_ADDR_HIGH
TBLPTRH
CODE_ADDR_LOW
MOVWF TBLPTRL
; Load TBLPTR with the base address
; The table pointer must be loaded with an even
address
MOVLW DATA0
MOVWF TABLAT
TBLWT*+
MOVLW DATA1
MOVWF TABLAT
TBLWT*
; LSB of word to be written
; MSB of word to be written
; The last table write must not increment the table
pointer! The table pointer needs to point to the
MSB before starting the write operation.
PROGRAM_MEMORY
BSF
BSF
BCF
MOVLW
Required MOVWF
Sequence MOVLW
MOVWF
BSF
BSF
BCF
BCF
EECON1, WPROG
EECON1, WREN
INTCON, GIE
0x55
EECON2
0xAA
EECON2
EECON1, WR
INTCON, GIE
EECON1, WPROG
EECON1, WREN
; enable single word write
; enable write to memory
; disable interrupts
; write 0x55
; write 0xAA
; start program (CPU stall)
; re-enable interrupts
; disable single word write
; disable write to memory
 2011 Microchip Technology Inc.
DS39931D-page 111