代码是手册上的那段,照搬程序,只是去掉了擦除后读命令校验,和写完后的读校验命令
每次只写一次时,上电调用数据,没事
但每次写完后,过一段时间再写,上电后再读就无效
void main()
{
WORD i;
BYTE j;
TMOD = 0x00; //timer0 in 16-bit auto reload mode
AUXR = 0x80; //timer0 working at 1T mode
TL0 = BAUD;
TH0 = BAUD>>8; //initial timer0 and set reload value
TR0 = 1; //tiemr0 start running
ET0 = 1; //enable timer0 interrupt
PT0 = 1; //improve timer0 interrupt priority
EA = 1; //open global interrupt switch
UART_INIT();
P1 = 0xfe; //1111111111111111,1111111110 System Reset OK
Delay(10); //Delay
UART_SEND(0x5a);
UART_SEND(0xa5);
IapEraseSector(IAP_ADDRESS); //Erase current sector
for (i=0; i<512; i++) //Check whether all sector data is FF
{
j = IapReadByte(IAP_ADDRESS+i);
UART_SEND(j);
// if (j != 0xff)
// goto Error; //If error, break
} P1 = 0xfc; //1111111111111111,111100 Erase successful
Delay(10); //Delay
for (i=0; i<512; i++) //Program 512 bytes data into data flash
{
IapProgramByte(IAP_ADDRESS+i, (BYTE)i);
}
P1 = 0xf8; //1111111111111111,1000 Program successful
Delay(10); //Delay
for (i=0; i<512; i++) //Verify 512 bytes data
{
j = IapReadByte(IAP_ADDRESS+i);
UART_SEND(j);
if (j != (BYTE)i)
goto Error; //If error, break
}
P1 = 0xf0; //1111111111111111,0000 Verify successful
while (1);
Error:
P1 &= 0x7f; //0xxx,xxxx IAP operation fail
while (1);
}
后来在每写一次后面加个软启动,问题没有了,但我知道这是在绕着问题走,根本的问题没有解决
|