void EEPROM_Busy(void)
{
while(EECON1bits.WR);
}
unsigned char EEPROM_Read_data(unsigned char address)
{
EEADR = (address & 0x0ff);
EECON1bits.CFGS = 0;
EECON1bits.EEPGD = 0;
EECON1bits.RD = 1;//软件置1,硬件清零
while(EECON1bits.RD);
EECON1bits.EEPGD = 1;
return EEDATA;
}
void EEPROM_Write_data(unsigned char data,unsigned char address)
{
EEADR = (address & 0x0ff);
EEDATA = data;
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
INTCONbits.GIEH = 0;
INTCONbits.GIEL = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;//软件置1,硬件清零
while(EECON1bits.WR);
EECON1bits.WREN = 0;
EECON1bits.EEPGD = 1;
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
}
void EEPROM_Read(char *data,unsigned char address,unsigned char n)
{
unsigned char i=0;
unsigned char addr=0;
addr=address;
for(i=0;i!=n;i++)
{
EEPROM_Read_data(addr);
*data=EEDATA;
addr++;
data++;
}
}
void EEPROM_Write(char *data,unsigned char address,unsigned char n)
{
unsigned char i=0;
unsigned char addr=0;
addr=address;
for(i=0;i!=n;i++)
{
EEPROM_Write_data(*data,addr);
addr++;
data++;
}
}
|