English
Language : 

PIC18F258 Datasheet, PDF (75/384 Pages) Microchip Technology – High Performance, 28/40-Pin Enhanced FLASH Microcontrollers with CAN
PIC18FXX8
EXAMPLE 6-3: WRITING TO FLASH PROGRAM MEMORY (CONTINUED)
WRITE_WORD_TO_HREGS
MOVFW POSTINC0, W
; get low byte of buffer data
MOVWF TABLAT
TBLWT+*
DECFSZ
BRA
PROGRAM_MEMORY
BSF
BCF
BSF
BCF
MOVLW
Required
MOVWF
Sequence
MOVLW
MOVWF
BSF
NOP
BSF
DECFSZ
BRA
BCF
COUNTER
WRITE_WORD_TO_HREGS
EECON1,EEPGD
EECON1,CFGS
EECON1,WREN
INTCON,GIE
55h
EECON2
0AAh
EECON2
EECON1,WR
INTCON,GIE
COUNTER_HI
PROGRAM_LOOP
EECON1,WREN
; present data to table latch
; write data, perform a short write
; to internal TBLWT holding register.
; loop until buffers are full
; point to FLASH program memory
; access FLASH program memory
; enable write to memory
; disable interrupts
; write 55H
; write 0AAH
; start program (CPU stall)
; re-enable interrupts
; loop until done
; disable write to memory
6.5.2 WRITE VERIFY
Depending on the application, good programming
practice may dictate that the value written to the mem-
ory should be verified against the original value. This
should be used in applications where excessive writes
can stress bits near the specification limit.
6.5.3
UNEXPECTED TERMINATION OF
WRITE OPERATION
If a write is terminated by an unplanned event, such as
loss of power or an unexpected RESET, the memory
location just programmed should be verified and repro-
grammed if needed.The WRERR bit is set when a write
operation is interrupted by a MCLR Reset, or a WDT
Time-out Reset during normal operation. In these situ-
ations, users can check the WRERR bit and rewrite the
location.
6.5.4
PROTECTION AGAINST SPURIOUS
WRITES
To reduce the probability against spurious writes to
FLASH program memory, the write initiate sequence
must also be followed. See Section 24.0, Special
Features of the CPU for more detail.
6.6 FLASH Program Operation During
Code Protection
See Section 24.0, Special Features of the CPU for
details on code protection of FLASH program memory.
 2002 Microchip Technology Inc.
Preliminary
DS41159B-page 73