STC内部EEPROM怎么存入多组数据

2024年11月22日 05:01
有1个网友回答
网友(1):

void read(uchar sq,unsigned char * eadd,unsigned char * nbadd,unsigned char size){
unsigned char i = size;
EA = 0;
while(i--){
IAP_ADDRH = sq; //0x10=使用第9扇区
IAP_ADDRL = (char)eadd;
IAP_CONTR = 0x80|IAP_WAIT_TIME; //11M
IAP_CMD = IAP_BYTE_READ; //读命令
IAP_TRIG = 0x5A;IAP_TRIG = 0xA5; //启动IAP
*nbadd = IAP_DATA;
nbadd++;eadd++;
}
IAP_CONTR = 0;
IAP_CMD = 0;
IAP_TRIG = 0;
IAP_ADDRH = 0xff; //重新指向第0扇区
EA = 1;
}
void save(uchar sq,unsigned char *eadd,unsigned char *nbadd,unsigned char size){
unsigned char i = size;
EA = 0;
weism |= dig[0]; //消隐
IAP_CONTR = 0x80|IAP_WAIT_TIME; //11M
IAP_ADDRH = sq; //0x10=第9扇区
IAP_ADDRL = 0x00;
IAP_CMD = IAP_SECTOR_ERASE; //擦除命令
IAP_TRIG = 0x5A;IAP_TRIG = 0xA5; //启动IAP
while(i--){
IAP_ADDRH = sq;
IAP_ADDRL = (char)eadd;
// IAP_CONTR = 0x80|IAP_WAIT_TIME; //11M
IAP_CMD = IAP_BYTE_PROG; //写入命令
IAP_DATA = *nbadd;
IAP_TRIG = 0x5A;IAP_TRIG = 0xA5; //启动IAP
nbadd++;eadd++;
}
IAP_CONTR = 0; //关闭IAP
IAP_CMD = 0;
IAP_TRIG = 0;
IAP_ADDRH = 0xff; //重新指向第0扇区
EA = 1;
}