在C51中调用的对STC的EEPROM操作的函数
/*$PAGE*/ /* *************************************************************************************************************** * * IspRead * Name : IspRead * Returns : none * Description : Read a string from EEPROM and Write them to the NumArray. *************************************************************************************************************** */ void IspRead(void) { unsigned char c;
EA = 0;
DPH = 0x10; DPL = 0x10;
ISP_CONTR = ENABLE_ISP; //允许ISP操作 ISP_CMD = ISP_BYTE_READ; //命令EEPROM读
for(RxCtr = 0;RxCtr<MAX_NUM ;RxCtr++){
ISP_ADDRH = DPH; ISP_ADDRL = DPL; _nop_();
ISP_TRIG = 0x46; ISP_TRIG = 0xB9;
_nop_(); c = ISP_DATA ; _nop_(); DacTal[RxCtr] = c;
DPL++; }
ISP_CONTR = 0x00; ISP_CMD = 0x00; ISP_TRIG = 0x00;
ISP_ADDRH = 0x00; ISP_ADDRL = 0x00;
RxCtr = 0; EA = 1; }
/*$PAGE*/ /* *************************************************************************************************************** * * IspWrite * Name : IspWrite * Returns : none * Description : Write a serial number to the EEPROM,Do it only while in CommISR. *************************************************************************************************************** */ void IspWrite(void) { unsigned char c;
IspErase();
DPH = 0x10; DPL = 0x10;
ISP_CONTR = ENABLE_ISP; //允许ISP操作 ISP_CMD = ISP_BYTE_WRITE; //命令EEPROM写
for(RxCtr = 0;RxCtr <MAX_NUM ;RxCtr++){
ISP_ADDRH = DPH; ISP_ADDRL = DPL;
c = DacTal[RxCtr]; ISP_DATA = c; _nop_();
ISP_TRIG = 0x46; ISP_TRIG = 0xB9;
_nop_();
DPL++; }
ISP_CONTR = 0x00; ISP_CMD = 0x00; ISP_TRIG = 0x00;
ISP_ADDRH = 0x00; ISP_ADDRL = 0x00;
RxCtr = 0; }
void IspErase(void) { ISP_ADDRH = 0x10; ISP_ADDRL = 0x00; _nop_();
ISP_CONTR = ENABLE_ISP; //允许ISP操作 ISP_CMD = ISP_SECTOR_ERASE; //命令EEPROM檫除 _nop_();
ISP_TRIG = 0x46; ISP_TRIG = 0xB9; _nop_(); ISP_CONTR = 0x00; ISP_CMD = 0x00; ISP_TRIG = 0x00;
ISP_ADDRH = 0x00; ISP_ADDRL = 0x00;
} |