/// eeprom读写程序,eeprom数据地址范围为(00-ff)
void Eeprom_Write(u8 u8Addr,u8 Buf)
{
EECON1bits.EEPGD = 0; // 选择eeprom访问
EECON1bits.CFGS = 0; // 选存取
EECON1bits.WREN = 1; // 允许写入数据
EEADR = u8Addr; // 地址
EEDATA = Buf; // 数据
EECON2 = 0X55;
EECON2 = 0XAA;
EECON1bits.WR = 1;
while(EECON1bits.WR); // 等待数据写入完毕
Nop();
Nop();
Nop();
Nop();
EECON1bits.WREN = 0;
}
u8 Eeprom_Read(u8 u8Addr)
{
u8 u8Data = 0;
EECON1bits.EEPGD = 0; // 选择eeprom访问
EECON1bits.CFGS = 0; // 选存取
EEADR = u8Addr; // 地址
EECON1bits.RD = 1; // 允许读数据
while(EECON1bits.RD);
Nop();
Nop();
Nop();
Nop();
u8Data = EEDATA;
EECON1bits.RD = 0;
return u8Data;
}