sfr IAP_DATA = 0xE2;
sfr IAP_ADDRH = 0xE3;
sfr IAP_ADDRL = 0xE4;
sfr IAP_CMD = 0xE5;
sfr IAP_TRIG = 0xE6;
sfr IAP_CONTR = 0xE7;
#define CMD_IDLE 0
#define CMD_READ 1
#define CMD_PROGRAM 2
#define CMD_ERASE 3
#define ENABLE_IAP0x80
#define ENABLE_IAP0x81
#define ENABLE_IAP0x82
#define ENABLE_IAP0x83
IAP_ADDRESS 0x2000 //STC90C52ϵÁÐEEPROM²âÊÔÆðʼµØÖ·
void IapIdle(void)
{
IAP_CONTR=0;
IAP_CMD =0;
IAP_TRIG =0;
IAP_ADDRH=0x80;
IAP_ADDRL =0;
}
unsigned char IapReadByte(unsigned int addt)
{
unsigned char dat;
IAP_CONTR=ENABLE_IAP;
IAP_CMD =CMD_READ;
IAP_ADDRL=addr;
IAP_ADDRL=addr>>8
IAP_TRIG =0x46;
IAP_TRIG =0xb9;
dat = IAP_DATA;
IapIdle();
return dat;
}
void Iap ProgramByte(unsigned int addr,unsigned char dat )
{
IAP_CONTR=ENABLE_IAP;
IAP_CMD =CMD_REOGRAM;
IAP_ADDRL=addr;
IAP_ADDRH=addr>>8
IAP_DATA=date;
IAP_TRIG =0x46;
IAP_TRIG =0xb9;
IapIdle();
}
void Iap EraseSector(unsigned int addr )
{
IAP_CONTR=ENABLE_IAP;
IAP_CMD =CMD_ERASE;
IAP_ADDRL=addr;
IAP_ADDRH=addr>>8
IAP_TRIG =0x46;
IAP_TRIG =0xb9;
IapIdle();
}
unsigned char Num=0;
void main(void)
{
unsigned long i=0;
Num = Iap ReadByte(IAP_ADDRESS+20);
Num++;
Iap EraseSector(IAP_ADDRESS);
Iap ProgramByte(IAP_ADDRESS+20,Num);
for(i=0;i
{
LED0=0;
DelayMs(100);
LED0=1;
DelayMs(100);
}
while(1);
}
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |