stc89c52中只擦除EEPROM的一个扇区怎么办

2024-11-22 20:46:20
推荐回答(1个)
回答1:

这是STC12c5A08AD的读写,8位的。16位的也简单分为两个八位就可以了,读出的时候在合并。
void byte_write(uchar high_add, uchar low_add, uchar w_data) // iap 字节写
{
IAP_DATA = w_data;
IAP_ADDRH = high_add;
IAP_ADDRL = low_add;
EA = 0;
_nop_();
IAP_CONTR = 0x81; //改 <24Mhz
IAP_CMD = 0x02;
_nop_();
IAP_TRIG = 0x5a;
_nop_();
IAP_TRIG = 0xa5;
_nop_();
IAP_CONTR = 0x00;
IAP_CMD = 0x00;
IAP_TRIG = 0x00;
IAP_ADDRH = 0xff;
IAP_ADDRL = 0xff;
EA = 1;
}

uchar byte_read(uchar high_add, uchar low_add) // iap 字节读
{
uchar return_data;
IAP_ADDRH = high_add;
IAP_ADDRL = low_add;
EA = 0;
_nop_();
IAP_CONTR = 0x81;
IAP_CMD = 0x01;
_nop_();
IAP_TRIG = 0x5a;
_nop_();
IAP_TRIG = 0xa5;
_nop_();
IAP_CONTR = 0x00;
IAP_CMD = 0x00;
IAP_TRIG = 0x00;
IAP_ADDRH = 0xff;
IAP_ADDRL = 0xff;
EA = 1;
return_data= IAP_DATA;
return return_data;
}

void sector_eraser(uchar high_add, uchar low_add) // iap 扇区擦除
{
IAP_ADDRH = high_add;
IAP_ADDRL = low_add;
EA = 0;
_nop_();
IAP_CONTR = 0x81;
IAP_CMD = 0x03;
_nop_();
IAP_TRIG = 0x5a;
_nop_();
IAP_TRIG = 0xa5;
_nop_();
IAP_CONTR = 0x00;
IAP_CMD = 0x00;
IAP_TRIG = 0x00;
IAP_ADDRH = 0xff;
IAP_ADDRL = 0xff;
EA = 1;
}