(EECON1<1>). The sequence in Example 4-4 must be
followed to initiate a write to program memory.
(parameter D133) in which the write takes place. This
continue to run. Therefore, the two instructions follow-
EECON, WR鈥?/div>
should be
NOP
instructions.
After the write cycle, the microcontroller will resume
operation with the 3rd instruction after the EECON1
write instruction.
A word of the FLASH program memory may only be
written to if the word is in a non-code protected seg-
ment of memory and the WRT configuration bit is set.
To write a FLASH program location, the first two bytes
of the address must be written to the EEADR and
EEADRH registers and two bytes of the data to the
EEDATA and EEDATH registers, set the EEPGD con-
EXAMPLE 4-4:
FLASH PROGRAM WRITE
BSF
BCF
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
MOVLW
MOVWF
BSF
BSF
BSF
STATUS, RP1
STATUS, RP0
ADDRH
EEADRH
ADDRL
EEADR
DATAH
EEDATH
DATAL
EEDATA
STATUS, RP0
EECON1, EEPGD
EECON1, WREN
;
; Bank 2
;
; MSByte of Program Address to read
;
; LSByte of Program Address to read
;
; MS Program Memory Value to write
;
; LS Program Memory Value to write
; Bank 3
; Point to PROGRAM memory
; Enable writes
BCF
MOVLW
Required
Sequence
MOVWF
MOVLW
MOVWF
BSF
INTCON, GIE
55h
EECON2
AAh
EECON2
EECON1, WR
; Disable Interrupts
;
; Write 55h
;
; Write AAh
; Set WR bit to begin write
NOP
NOP
; Instructions here are ignored by the microcontroller
; Microcontroller will halt operation and wait for
; a write complete. After the write
; the microcontroller continues with 3rd instruction
BSF
BCF
INTCON,
GIE
; Enable Interrupts
; Disable writes
EECON1, WREN
4.7
Write Verify
Depending on the application, good programming prac-
tice may dictate that the value written to the memory
should be verified against the original value. This
should be used in applications where excessive writes
can stress bits near the specification limit.
Generally a write failure will be a bit which was written
as a '1', but reads back as a '0' (due to leakage off the
bit).
漏
1999 Microchip Technology Inc.
DS30292B-page 45