1.stc-isp软件中自带的EEPROM例程是对应STC11,不同的stc型号的EEPROM的大小是不同的,stc12c5a60s2片上EEPROM的大小是1KB.
STC-ISP型号参数查阅stc12系列的PDF手册
EERPOM大小及起始结束地址由上图可知STC12C5A60S2 EEPROM的地址范围为:0x0000---0x03ff
(0-1023)
范例在范例中给的IAP_ADDRESS地址为0x0400,故直接使用的话会写不成功。
在修改为0x0000后程序读完正常。
STC-ISP界面在STC-ISP软件中可以设定EEPROM的内容,起始地址 和结束地址对应EEPROM的地址范围,填充数据可以自行设定。设定好后保存数据为*.bin文件,再打开EEPROM文件 再点击下载即可。
void IapIdle()
{
IAP_CONTR = 0; //Close IAP function
IAP_CMD = 0; //Clear command to standby
IAP_TRIG = 0; //Clear trigger register
IAP_ADDRH = 0x80; //Data ptr point to non-EEPROM area
IAP_ADDRL = 0; //Clear IAP address to prevent misuse
}
BYTE IapReadByte(WORD addr)
{
BYTE dat; //Data buffer
IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time
IAP_CMD = CMD_READ; //Set ISP/IAP/EEPROM READ command
IAP_ADDRL = addr; //Set ISP/IAP/EEPROM address low
IAP_ADDRH = addr >> 8; //Set ISP/IAP/EEPROM address high
IAP_TRIG = 0x5a; //Send trigger command1 (0x5a)
IAP_TRIG = 0xa5; //Send trigger command2 (0xa5)
_nop_(); //MCU will hold here until ISP/IAP/EEPROM operation complete
dat = IAP_DATA; //Read ISP/IAP/EEPROM data
IapIdle(); //Close ISP/IAP/EEPROM function
return dat; //Return Flash data
}
void IapProgramByte(WORD addr, BYTE dat)
{
IAP_DATA = dat;
IAP_ADDRL = addr; //Set ISP/IAP/EEPROM address low
IAP_ADDRH = addr >> 8;
IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time
IAP_CMD = CMD_PROGRAM; //Set ISP/IAP/EEPROM PROGRAM command
//Set ISP/IAP/EEPROM address high
//Write ISP/IAP/EEPROM data
IAP_TRIG = 0x5a; //Send trigger command1 (0x5a)
IAP_TRIG = 0xa5; //Send trigger command2 (0xa5)
_nop_(); //MCU will hold here until ISP/IAP/EEPROM operation complete
IapIdle();
}
void IapEraseSector(WORD addr)
{
IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time
IAP_CMD = CMD_ERASE; //Set ISP/IAP/EEPROM ERASE command
IAP_ADDRL = addr; //Set ISP/IAP/EEPROM address low
IAP_ADDRH = addr >> 8; //Set ISP/IAP/EEPROM address high
IAP_TRIG = 0x5a; //Send trigger command1 (0x5a)
IAP_TRIG = 0xa5; //Send trigger command2 (0xa5)
_nop_(); //MCU will hold here until ISP/IAP/EEPROM operation complete
IapIdle();
}
主要的寄存器有【IAP_CONTR】【IAP_CMD】【IAP_ADDRH】【IAP_ADDRL】【IAP_TRIG】【IAP_DATA】
网友评论