English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (122/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
7.4.1 PROGRAMMING ALGORITHM
The user can program one row of program Flash memory
at a time. To do this, it is necessary to erase the 8-row
erase block containing the desired row. The general
process is:
1. Read eight rows of program memory
(1024 instructions) and store in data RAM.
2. Update the program data in RAM with the
desired new data.
3. Erase the page (see Example 7-1):
4. Write the first 128 words from data RAM into the
program memory buffers (see Example 7-1).
5. Repeat steps 4 and 5, using the next available
128 words from the block in data RAM by incre-
menting the value in NVMADDR and
NVMASRCADDR, until all 1024 instructions are
written back to Flash memory.
For protection against accidental operations, the write
initiate sequence for NVMKEY must be used to allow
any erase or program operation to proceed. After the
programming command has been executed, the user
must wait for the programming time until programming
is complete.
EXAMPLE 7-1: ERASING FLASH PAGE
unsigned int NVMUnlock (unsigned int nvmop)
{
unsigned int status;
// Suspend or Disable all Interrupts
asm volatile (“di %0” : “=r” (status));
// Enable Flash Write/Erase Operations and Select
// Flash operation to perform
NVMCON = nvmop;
// Write Keys
NVMKEY = 0xAA996655;
NVMKEY = 0x556699AA;
// Start the operation using the Set Register
NVMCONSET = 0x8000;
// Wait for operation to complete
while (NVMCON & 0x8000);
// Restore Interrupts
if (status & 0x00000001
asm volatile (“ei”);
else
asm volatile (“di”);
// Return NVMERR and LVDERR Error Status Bits
return (NVMCON & 0x3000)
}
unsigned int NVMErasePage(void* address)
{
unsigned int res;
// Set NVMADDR to the Start Address of page to erase
NVMADDR = (unsigned int) address;
// Unlock and Erase Page
res = NVMUnlock(0x4004);
// Return Result
return res;
}
DS61143E-page 120
Preliminary
© 2008 Microchip Technology Inc.