给一个STC8的作为参考
u8 iap_byte_rd(u16 addr)
{
u8 tmp;
F0 = EA;
EA = 0;
IAP_CONTR = 0x80;
IAP_CMD = 1;
IAP_ADDRH = (u8)(addr >> 8);
IAP_ADDRL = addr;
IAP_TRIG = 0x5a;
IAP_TRIG = 0xa5;
_nop_();
tmp = IAP_DATA;
IAP_CONTR = 0;
IAP_CMD = 0;
IAP_TRIG = 0;
IAP_ADDRH = 0xff;
IAP_ADDRL = 0xff;
EA = F0;
return tmp;
}
void iap_byte_wr(u16 addr, u8 val)
{
F0 = EA;
EA = 0;
IAP_CONTR = 0x80;
IAP_CMD = 2
IAP_ADDRH = (u8)(addr >> 8);
IAP_ADDRL = addr;
IAP_DATA = val;
IAP_TRIG = 0x5a;
IAP_TRIG = 0xa5;
_nop_();
IAP_CONTR = 0;
IAP_CMD = 0;
IAP_TRIG = 0;
IAP_ADDRH = 0xff;
IAP_ADDRL = 0xff;
EA = F0;
}
void iap_sec_erase(u16 addr)
{
F0 = EA;
EA = 0;
IAP_ADDRH = (u8)(addr >> 8);
IAP_ADDRL = addr;
IAP_CONTR = 0x80;
IAP_CMD = 3;
IAP_TRIG = 0x5a;
IAP_TRIG = 0xa5;
_nop_();
IAP_CONTR = 0;
IAP_CMD = 0;
IAP_TRIG = 0;
IAP_ADDRH = 0xff;
IAP_ADDRL = 0xff;
EA = F0;
} |