void eeprom_erase(uint addr)
{
//CY = EA;
EA = 0;
FLASHCON = 1; //·ÃÎÊEEPROMÇø
XPAGE = addr;
IB_CON1 = 0xe6;
IB_CON2 = 0x05;
IB_CON3 = 0x0a;
IB_CON4 = 0x09;
IB_CON5 = 0x06;
_nop_();
_nop_();
_nop_();
_nop_();
XPAGE = 0;
FLASHCON = 0; //·ÃÎÊÖ÷³ÌÐò
EA=1;
}
void eeprom_program(uint addrH,uint addrL,uint ndata)
{
//CY = EA;
EA = 0;
FLASHCON = 1;
XPAGE = addrH;
IB_OFFSET = addrL;
IB_DATA = ndata;
IB_CON1 = 0x6e;
IB_CON2 = 0x05;
IB_CON3 = 0x0a;
IB_CON4 = 0x09;
IB_CON5 = 0x06;
_nop_();
_nop_();
_nop_();
_nop_();
XPAGE = 0;
FLASHCON = 0;
EA=1;
}
void eeprom_write(uint addr,uchar *value,uchar num)
{
uchar n=0;
eeprom_erase(addr>>8);
for(n=0;n<num;n++)
{
eeprom_program(addr>>8,(addr&0x0f),value[n]);
addr++;
}
}
uchar eeprom_read(uint addr)
{
uint tempb;
FLASHCON = 1;
tempb = *(uchar code *)(addr);
FLASHCON = 0;
return (tempb);
}
|