************************** write eeprom ************************/
void WriteEEP (unsigned char AH,unsigned char AL,unsigned char DA)
{
while (EECON1bits.WR = =True ) ; //
EEADRH = AH ; // Upper bits of Data Memory Address to write
EEADR = AL ; // Lower bits of Data Memory Address to write
EEDATA = DA ; // Data Memory Value to write
EECON1bits.EEPGD = False ;
EECON1bits.CFGS = False ;
EECON1bits.WREN = True ;
INTCONbits.GIE = False ;
EECON2 = 0X55 ;
Nop();
EECON2 = 0XAA ;
EECON1bits.WR = True ; // Set WR bit to begin write
INTCONbits.GIE = True; // Enable Interrupts
EECON1bits.WREN = False ; // Disable writes on write complete
}
/*************************** read eeprom ***********************/
unsigned char ReadEEP ( unsigned char AH,unsigned char AL)
{ EEADRH= AH;
EEADR = AL;
EECON1bits.EEPGD = False ; // Point to DATA memory
EECON1bits.CFGS = False ; // Access EEPROM
EECON1bits.RD = True; // EEPROM Read
return(EEDATA);
}
连续写的时候,写的数据不正确,在写eep后加一个5ms的延时,才能正确的写入。
文章评论(0条评论)
登录后参与讨论