1947
void WriteEE(unsigned char adds,unsigned char data)
{
while(WR==1); //上一次写操作是否完成
EEADR=adds; //EEPROM地址
EEDAT=data;
//准备写入EEPROM的数据
EEPGD=0; //指向EEPROM数据储存器
CFGS=0;
//指向EEPROM数据储存器
WREN=1; //使能写操作
GIE=0; //禁止中断
EECON2=0x55;
EECON2=0xAA; //EEPROM解锁
WR=1;
GIE=1; //开始写
while(WR==1); //等待写操作完成
if(EEIF==1)
EEIF=0;
WREN=0; //禁止写操作
}
unsigned char ReadEE(unsigned char adds)
{
unsigned char num;
while(RD==1); //上一次读操作是否完成
EEADR=adds; //EEPROM地址为00H
EEPGD=0; //指向EEPROM数据储存器
CFGS=0;
//指向EEPROM数据储存器
RD=1; //开始读
while(RD==1); //等待读操作完成
num=EEDAT; //读出
return(num); //返回读出的数
}
690
void write_eeprom(unsigned char data, unsigned char add )
{
//while(WR==1);
EEADR=add;
EEDAT=data; //欲写入之数据
EEPGD=0x00; //操作数据EEPROM区
WREN=0x01; //使能写操作
GIE=0x00; //禁止中断
EECON2=0x55;
EECON2=0xAA;
WR=0x01;
GIE=0x01;
// delay(0x02);
while(WR==1);
if(EEIF==1)
EEIF=0;
WREN=0x00;
}
unsigned char read_eeprom(unsigned add)
{ unsigned char num;
while(RD==1);
EEADR=add; //寻址地址
EEPGD=0x00; //操作数据EEPROM区
RD=0x01; //启动读操作
// return EEDAT;
while(RD==1); //等待读操作完成
num=EEDAT; //读出
return(num);
}
初始化
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);
__EEPROM_DATA(0,0,0,0,0,0,0,0);