dsPIC30F Family Reference Manual
DS70052C-page 5-16 © 2004 Microchip Technology Inc.
5.5.3 Erasing One Word of Data EEPROM Memory
The TBLPAG and NVMADR registers must be loaded with the data EEPROM address to be
erased. Since one word of the EEPROM is accessed, the LSB of the NVMADR has no effect on
the erase operation. The NVMCON register must be configured to erase one word of EEPROM
memory.
Setting the WR control bit (NVMCON<15>) initiates the erase. A special unlock or key sequence
should be written to the NVMKEY register before setting the WR control bit. The unlock sequence
needs to be executed in the exact order shown without interruption. Therefore, interrupts should
be disabled prior to writing the sequence.
; Set up a pointer to the EEPROM location to be erased.
MOV #tblpage(EE_ADDR),W0
MOV W0
,
TBLPAG
MOV #tbloffset(EE_ADDR),W0
MOV W0,NVMADR
; Setup NVMCON to erase one word of data EEPROM
MOV #0x4044,W0
MOV W0
,
NVMCON
; Disable interrupts while the KEY sequence is written
PUSH SR
MOV #0x00E0,W0
IOR SR
; Write the KEY sequence
MOV #0x55,W0
MOV W0,NVMKEY
MOV #0xAA,W0
MOV W0,NVMKEY
; Start the erase cycle
BSET NVMCON,#WR
; Re-enable interrupts
POP SR