unsigned char EEPROMread(unsigned char EEAddr)
{ //读EEPROM
unsigned char EEPROMdata;
EEADR = EEAddr; // 要读的EEPROM的地址,地址要在0-FF间
RD = 1; //开启读功能
EEPROMdata = EEDAT; //EEPROM 的读数据 ReEEPROMread = EEDATA;
return EEPROMdata; //返回EEPROM数据
}
void EEPROMwrite(unsigned char ddr,unsigned char Data)
{ //写EEPROM
GIE = 0; //写数据必须关闭中断
while(GIE); //等待 GIE 为 0
EEADR = ddr; //EEPROM 的地址,地址要在0-FF间
EEDAT = Data; //EEPROM 的写数据 EEDATA = Data;
EEIF = 0;
EECON1 |= 0x34; //置位 WREN1,WREN2,WREN3 三个变量.
WR = 1; //置位 WR 启动编程
while(WR); //等待 EE 写入完成
GIE = 1;
}
void DelayUs( unsigned char Time)
//US 短延时函数
{ unsigned char a;
for(a=0;a<Time;a++)
{
NOP();
}
}
void DelayMs(unsigned char Time)
{ //MS 延时函数
unsigned char a;
unsigned char b;
for(a=0;a<Time;a++)
{ for(b=0;b<250;b++)
{NOP();
NOP();
NOP();
NOP();
}
}
}
|