English
Language : 

PIC18LF24K Datasheet, PDF (142/594 Pages) –
PIC18(L)F26/45/46K40
11.3.5 WRITE VERIFY
Depending on the application, good programming
practice 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.
EXAMPLE 11-5: DATA EEPROM READ
; Data Memory Address to read
BCF NVMCON1, NVMREG0
BCF NVMCON1, NVMREG1
MOVF EE_ADDRL, W
MOVWF NVMADRL
MOVF EE_ADDRH, W
MOVWF NVMADRH
BSF NVMCON1, RD
MOVF NVMDAT, W
; Setup Data EEPROM Access
; Setup Data EEPROM Access
;
; Setup Address low byte
;
; Setup Address high byte (if applicable)
; Issue EE Read
; W = EE_DATA
EXAMPLE 11-6: DATA EEPROM WRITE
; Data Memory Address to write
BCF
NVMCON1, NVMREG0 ; Setup Data EEPROM access
BCF
NVMCON1, NVMREG1 ; Setup Data EEPROM access
MOVF
EE_ADDRL, W
;
MOVWF
NVMADRL
; Setup Address low byte
MOVF
EE_ADDRH, W
;
MOVWF
NVMADRH
; Setup Address high byte (if applicable)
; Data Memory Value to write
MOVF
EE_DATA, W
;
MOVWF
NVMDAT
;
; Enable writes
BSF
NVMCON1, WREN ;
; Disable interrupts
BCF
INTCON, GIE
;
; Required unlock sequence
MOVLW
55h
;
MOVWF
NVMCON2
;
MOVLW
AAh
;
MOVWF
NVMCON2
;
; Set WR bit to begin write
BSF
NVMCON1, WR
;
; Wait for write to complete
BTFSC
NVMCON1, WR
BRA
$-2
; Enable INT
BSF
INTCON, GIE
;
; Disable writes
BCF
NVMCON1, WREN ;
 2016 Microchip Technology Inc.
Preliminary
DS40001816C-page 142