下面是我用的flash擦除程序,用软件仿真的时候可以擦除掉给定地址的扇区,但在线调试的时候发现程序一运行到*pwrite = 1; 语句时就会自动复位,没有实现擦除,不知道是怎么回事,求大神们帮忙啊!
void ClrFlash(uint addr)
{
char xdata * data pwrite;
EA = 0; //Disable interrupts
//change clock speed to slow, then restore later
VDM0CN = 0x80; // Enable VDD monitor
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 = 0x80; // Enable VDD monitor
RSTSRC = 0x02; // Enable VDD monitor as a reset source
*pwrite = 1; // Initiate page erase
PSCTL &= ~0x03; // PSWE = 0; PSEE = 0
EA = 1; //Restore interrupts
}
此帖出自
小平头技术问答
//
//flashò3Çå3y
//2Îêy£oÄ¿±êμØÖ·
//·μ»Ø£o0£o꧰ü£¬1£o3é1|
//Time£o2013.12.16
//
//***********************************************************************************************
unsigned char Flash_PageErase (FLASHADDR addr)
{
bit EA_SAVE = EA; // Preserve EA
unsigned char xdata * data pwrite; // FLASH write pointer
unsigned char i;
EA = 0;
RSTSRC = 0x00;
VDM0CN = 0xA0;
for (i = 0; i < 255; i++);
if (!(VDM0CN & 0x40))
return 1;
RSTSRC = 0x02;
pwrite = (unsigned char xdata *) addr;
FLKEY = 0xA5; // Key Sequence 1
FLKEY = 0xF1; // Key Sequence 2
PSCTL |= 0x03; // PSWE = 1; PSEE = 1
VDM0CN = 0xA0;
RSTSRC = 0x02;
*pwrite = 1;
RSTSRC = 0x00;
VDM0CN = 0x80;
RSTSRC = 0x02;
PSCTL &= ~0x03;
EA = EA_SAVE;
return 0;
}
一周热门 更多>