STC15F10XX的单片机写eeprom时的问题请教

[复制链接]
3172|5
 楼主| gurong60 发表于 2011-10-19 09:52 | 显示全部楼层 |阅读模式
如题,
1.上电,擦除,写入,读出。没有问题
2.上电,擦除,写入,擦除,写入。数据全丢
请问为何?
fu10 发表于 2011-10-19 12:18 | 显示全部楼层
本帖最后由 fu10 于 2011-10-19 12:20 编辑

以前用过,都有点忘了,帮顶一下
john_light 发表于 2011-10-19 12:23 | 显示全部楼层
写入之后尝试读回检查是否成功吗?
yewuyi 发表于 2011-10-19 13:34 | 显示全部楼层
这显然要看你的代码和数据手册去了。
autopccopy 发表于 2011-10-19 14:09 | 显示全部楼层
检查电源、复位和代码吧,没有这个理由的。:L
 楼主| gurong60 发表于 2011-10-20 09:23 | 显示全部楼层
代码是手册上的那段,照搬程序,只是去掉了擦除后读命令校验,和写完后的读校验命令
每次只写一次时,上电调用数据,没事
但每次写完后,过一段时间再写,上电后再读就无效

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);
}


后来在每写一次后面加个软启动,问题没有了,但我知道这是在绕着问题走,根本的问题没有解决
您需要登录后才可以回帖 登录 | 注册

本版积分规则

179

主题

1308

帖子

4

粉丝
快速回复 在线客服 返回列表 返回顶部