Board logo

标题: 求助:使用EEPROM记录数据出错,请高手指点,谢谢! [打印本页]

作者: terencejia111    时间: 2008-8-22 08:22     标题: 求助:使用EEPROM记录数据出错,请高手指点,谢谢!

下面是我使用的EEPROM的程序,想记录一些数据,但是每次都不对,单片机运行正常,不知道是哪儿出了问题,请大虾们指点迷津,谢谢!

#define eclkdiv (*((volatile unsigned char*)(0x0110)))
#define ecnfg (*((volatile unsigned char*)(0x0113)))
#define eprot (*((volatile unsigned char*)(0x0114)))
#define estat (*((volatile unsigned char*)(0x0115)))
#define ecmd (*((volatile unsigned char*)(0x0116)))
unsigned char relative_addr;
#define EE_BASE ((volatile unsigned int*)(0x2000))
volatile unsigned int * ee_addr = EE_BASE;
void wreeprom(void) {
//put your own code here
ECLKDIV = 0x4b;
while(!(ECLKDIV&0x80));
while(!(ESTAT&0x80));
while(!(EPROT&0x80));

for(relative_addr=0;relative_addr<14;relative_addr++)
{
*ee_addr = (int)(unit[relative_addr]*100);
ee_addr=ee_addr+1;
ECMD = 0x20;
ESTAT |= 0x80;
while(!(ESTAT&0x40));
}
*ee_addr = time2;
ee_addr=ee_addr+1;
ECMD = 0x20;
ESTAT |= 0x80;
while(!(ESTAT&0x40));
*ee_addr = PACN10;
ee_addr=ee_addr+1;
ECMD = 0x20;
ESTAT |= 0x80;
while(!(ESTAT&0x40));

}


作者: strongchen    时间: 2008-8-25 17:36

你用的是什么芯片?EEPROM地址对吗?




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0