void FLASH_PageErase (FLADDR addr)
{
bit EA_SAVE = EA; // Preserve EA
char xdata * data pwrite; // FLASH write pointer
EA = 0; // Disable interrupts
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
RSTSRC = 0x02; // Enable VDD monitor as a reset source
pwrite = (char xdata *) addr;
FLKEY = 0xA5; // Key Sequence 1
FLKEY = 0xF1; // Key Sequence 2
PSCTL |= 0x03; // PSWE = 1; PSEE = 1
VDM0CN = 0xA0; // Enable VDD monitor and high threshold
RSTSRC = 0x02; // Enable VDD monitor as a reset source
*pwrite = 0; // Initiate page erase
PSCTL &= ~0x03; // PSWE = 0; PSEE = 0
EA = EA_SAVE; // Restore interrupts
}
只有在 addr=0的时候会成功,其它地址,程序都会停止 *pwrite = 0; // Initiate page erase 这条语句。
|