PIC24FV16KM204 FAMILY
DS33030A-page 76
Advance Information
2013 Microchip Technology Inc.
6.4.1
ERASE DATA EEPROM
The data EEPROM can be fully erased, or can be
partially erased, at three different sizes: one word, four
words or eight words. The bits, NVMOP<1:0>
(NVMCON<1:0>), decide the number of words to be
erased. To erase partially from the data EEPROM, the
following sequence must be followed:
1.
Configure NVMCON to erase the required
number of words: one, four or eight.
2.
Load TBLPAG and WREG with the EEPROM
address to be erased.
3.
Clear the NVMIF status bit and enable the NVM
interrupt (optional).
4.
Write the key sequence to NVMKEY.
5.
Set the WR bit to begin the erase cycle.
6.
Either poll the WR bit or wait for the NVM
interrupt (NVMIF is set).
A typical erase sequence is provided in
This example shows how to do a one-word erase.
Similarly, a four-word erase and an eight-word erase
can be done. This example uses C library procedures to
manage the Table Pointer (
builtin_tblpage
and
builtin_tbloffset
) and the Erase Page Pointer
(
builtin_tblwtl
). The memory unlock sequence
(
builtin_write_NVM
) also sets the WR bit to initiate
the operation and returns control when complete.
EXAMPLE 6-2:
SINGLE-WORD ERASE
int __attribute__ ((space(eedata))) eeData = 0x1234;
/*--------------------------------------------------------------------------------------------
The variable eeData must be a Global variable declared outside of any method
the code following this comment can be written inside the method that will execute the erase
----------------------------------------------------------------------------------------------
*/
unsigned int offset;
// Set up NVMCON to erase one word of data EEPROM
NVMCON = 0x4058;
// Set up a pointer to the EEPROM location to be erased
TBLPAG = __builtin_tblpage(&eeData);
// Initialize EE Data page pointer
offset = __builtin_tbloffset(&eeData);
// Initizlize lower word of address
__builtin_tblwtl(offset, 0);
// Write EEPROM data to write latch
asm volatile ("disi #5");
// Disable Interrupts For 5 Instructions
__builtin_write_NVM();
// Issue Unlock Sequence & Start Write Cycle
while(NVMCONbits.WR=1);
// Optional: Poll WR bit to wait for
// write sequence to complete
Summary of Contents for PIC24FV16KM204 FAMILY
Page 312: ...PIC24FV16KM204 FAMILY DS33030A page 312 Advance Information 2013 Microchip Technology Inc ...
Page 313: ... 2013 Microchip Technology Inc Advance Information DS33030A page 313 PIC24FV16KM204 FAMILY ...
Page 315: ... 2013 Microchip Technology Inc Advance Information DS33030A page 315 PIC24FV16KM204 FAMILY ...
Page 316: ...PIC24FV16KM204 FAMILY DS33030A page 316 Advance Information 2013 Microchip Technology Inc ...
Page 317: ... 2013 Microchip Technology Inc Advance Information DS33030A page 317 PIC24FV16KM204 FAMILY ...
Page 322: ...PIC24FV16KM204 FAMILY DS33030A page 322 Advance Information 2013 Microchip Technology Inc ...