4.6 Functions for Erasing and Writing Flash Memory
These functions support the erasing and writing of Flash memory for devices that have this type of memory.
Example of Use
Example 1: dsPIC30F DSCs
#include "libpic30.h"
#include "p30fxxxx.h"
int __attribute__((space(prog),aligned(_FLASH_PAGE*2))) dat[_FLASH_PAGE];
int main() {
int i;
int source1[_FLASH_ROW];
long source2[_FLASH_ROW];
_prog_addressT p;
for (i = 0; i < _FLASH_ROW; ) {
source1[i] = i;
source2[i] = i++;
} /* initialize some data */
_init_prog_address(p, dat); /* get address in program space */
_erase_flash(p); /* erase a page */
_write_flash16(p, source1); /* write first row with 16-bit data */
_erase_flash(p); /* on dsPIC30F, only 1 row per page */
_write_flash24(p, source2); /* write second row with 24-bit data */
}