15.16 Page Erase
A Page Erase performs an erase of a single page of either PFM or BFM.
The page to be erased is selected using the NVMADDR register. Pages are always erased on page boundaries; therefore, for a device with an instruction Word page size of 4096, the user can ignore the bits 0 through 11 of the NVMADDR register.
A Page Erase only succeeds, if the target address is a page that is not write-protected. Erasing a write-protected page fails and result in the WRERR bit being set in the NVMCON register.
The following code shows the code for a single Page Erase operation at address 0x1008000.
…
// set destination page address
NVMADDR = 0x1008000; // page physical address
// define Flash operation
NVMCONbits.NVMOP = 0x4; // NVMOP for Page Erase
// Enable Flash Write
NVMCONbits.WREN = 1;
// commence programming
NVMInitiateOperation(); // see Initiate NVM Operation (Unlock Sequence Example)
// Wait for WR bit to clear
while(NVMCONbits.WR);
// Disable future Flash Write/Erase operations
NVMCONbits.WREN = 0;
// Check Error Status
if(NVMCON & 0x3000) // mask for WRERR and LVDERR bits
{
// process errors
}
…