用的N76E003芯片,下载了最新版2017版的IAP_Dataflash_EEPROM,测试任何值写入,再读都为0,找了2016版的例程测试,读出数据正确,仔细对比了代码,发现两个版本有一些不同
2017版
void write_DATAFLASH_BYTE(UINT16 u16_addr,UINT8 u8_data)
{
UINT8 looptmp=0,u8_addrl_r;
unsigned char code *cd_longaddr;
unsigned char xdata *xd_tmp;
//Check page start address
u8_addrl_r = u16_addr;
if (u8_addrl_r<0x80)
{
u8_addrl_r = 0;
}
else
{
u8_addrl_r = 0x80;
}
//Save APROM data to XRAM
xd_tmp = 0x80; //不同点
cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;
while (xd_tmp !=0x100) //不同点
{
*xd_tmp = *cd_longaddr;
looptmp++;
xd_tmp++;
cd_longaddr++;
}
// Modify customer data in XRAM
u8_addrl_r = u16_addr;
if (u8_addrl_r<0x80)
{
xd_tmp = u8_addrl_r+0x80; //不同点
}
else
{
xd_tmp = u8_addrl_r+0; //不同点
}
*xd_tmp = u8_data;
//Erase APROM DATAFLASH page
IAPAL = u16_addr;
IAPAH = u16_addr>>8;
IAPFD = 0xFF;
set_IAPEN;
set_APUEN;
IAPCN = 0x22;
set_IAPGO;
//Save changed RAM data to APROM DATAFLASH
u8_addrl_r = u16_addr;
if (u8_addrl_r<0x80)
{
u8_addrl_r =0;
}
else
{
u8_addrl_r = 0x80;
}
xd_tmp = 0x280;
IAPAL = u8_addrl_r;
IAPAH = u16_addr>>8;
set_IAPEN;
set_APUEN;
IAPCN = 0x21;
while (xd_tmp !=0xFF)
{
IAPFD = *xd_tmp;
set_IAPGO;
IAPAL++;
xd_tmp++;
}
clr_APUEN;
clr_IAPEN;
}
2016版
void write_DATAFLASH_BYTE(UINT16 u16_addr,UINT8 u8_data)
{
UINT8 looptmp=0,u8_addrl_r;
unsigned char code *cd_longaddr;
unsigned char xdata *xd_tmp;
//Check page start address
u8_addrl_r = u16_addr;
if (u8_addrl_r<0x80)
{
u8_addrl_r = 0;
}
else
{
u8_addrl_r = 0x80;
}
//Save APROM data to XRAM
xd_tmp = 0x280;
cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;
while (xd_tmp !=0x300)
{
*xd_tmp = *cd_longaddr;
looptmp++;
xd_tmp++;
cd_longaddr++;
}
// Modify customer data in XRAM
u8_addrl_r = u16_addr;
if (u8_addrl_r<0x80)
{
xd_tmp = u8_addrl_r+0x280;
}
else
{
xd_tmp = u8_addrl_r+0x200;
}
*xd_tmp = u8_data;
//Erase APROM DATAFLASH page
IAPAL = u16_addr;
IAPAH = u16_addr>>8;
IAPFD = 0xFF;
set_IAPEN;
set_APUEN;
IAPCN = 0x22;
set_IAPGO;
//Save changed RAM data to APROM DATAFLASH
u8_addrl_r = u16_addr;
if (u8_addrl_r<0x80)
{
u8_addrl_r =0;
}
else
{
u8_addrl_r = 0x80;
}
xd_tmp = 0x280;
IAPAL = u8_addrl_r;
IAPAH = u16_addr>>8;
set_IAPEN;
set_APUEN;
IAPCN = 0x21;
while (xd_tmp !=0x2FF)
{
IAPFD = *xd_tmp;
set_IAPGO;
IAPAL++;
xd_tmp++;
}
clr_APUEN;
clr_IAPEN;
}
新版修改那4个数值是什么意义? |