Microchip Technology DM183037 데이터 시트

다운로드
페이지 696
 2012 Microchip Technology Inc.
DS30575A-page 151
PIC18F97J94 FAMILY
7.5.2
FLASH PROGRAM MEMORY WRITE 
SEQUENCE (WORD PROGRAMMING)
The PIC18F97J94 family of devices has a feature that
allows programming a single word (two bytes). This
feature is enabled when the WWPROG 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 WWPROG bit (EECON1<5>) to
select Word Write mode.
4.
Disable interrupts.
5.
Write 55h to EECON2.
6.
Write 0AAh 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
T
IW 
(see Paramete
9.
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 
; The table pointer must be loaded with an even address
MOVWF
TBLPTRL
MOVLW
DATA0 
; LSB of word to be written
MOVWF
TABLAT
TBLWT*+
MOVLW
DATA1 
; MSB of word to be written
MOVWF
TABLAT
TBLWT* 
; 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
EECON1, WWPROG 
; 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 AAh
BSF 
EECON1, WR 
; start program (CPU stall)
BSF
INTCON, GIE 
; re-enable interrupts
BCF
EECON1, WWPROG 
; disable single word write
BCF
EECON1, WREN 
; disable write to memory