读写对比,调试查看寄存器 一点问题没有
一烧到单片机全速运行 对比就出错
unsigned char HF_Read_b_eep( unsigned int badd )
{
do{}
while(EECON1bits.RD);
EEADRH = (badd >> 8) & 0x03;
EEADR = (badd & 0x0ff);
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.RD = 1;
do{}
while(EECON1bits.RD);
Nop(); //Nop may be required for latency at high frequencies
Nop(); //Nop may be required for latency at high frequencies
return ( EEDATA ); // return with read byte
}
void HF_Write_b_eep( unsigned int badd,unsigned char bdat )
{
do{}
while(EECON1bits.WR); //Wait till the write completion
char GIE_BIT_VAL = 0;
EEADRH = (badd >> 8) & 0x03;
EEADR = (badd & 0x0ff);
EEDATA = bdat;
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
GIE_BIT_VAL = INTCONbits.GIE;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
do{}
while(EECON1bits.WR); //Wait till the write completion
INTCONbits.GIE = GIE_BIT_VAL;
EECON1bits.WREN = 0;
} |