在使用PIC16F18344的内部eeprom时,写入数据,然后读出来,很多地址的数据都不对,这会什么原因?中断已经关闭。
void DATAEE_WriteByte(uint8_t bAdd, uint8_t bData)
{
uint8_t GIEBitValue = INTCONbits.GIE;
NVMADRH = 0;
NVMADRL = bAdd; //+ EEP_OFFSET;
NVMDATL = bData;
NVMCON1bits.NVMREGS = 1;
NVMCON1bits.WREN = 1;
INTCONbits.GIE = 0; // Disable interrupts
NVMCON2 = 0x55;
NVMCON2 = 0xAA;
NVMCON1bits.WR = 1;
NOP(); // NOPs may be required for latency at high frequencies
NOP();
// Wait for write to complete
while (NVMCON1bits.WR)
{
}
NVMCON1bits.WREN = 0;
INTCONbits.GIE = GIEBitValue; // restore interrupt enable
}
uint8_t DATAEE_ReadByte(uint8_t bAdd)
{
NVMADRH = 0;
NVMADRL = bAdd; //+ EEP_OFFSET;
NVMCON1bits.NVMREGS = 1;
NVMCON1bits.RD = 1;
NOP(); // NOPs may be required for latency at high frequencies
NOP();
NOP(); // NOPs may be required for latency at high frequencies
NOP();
return (NVMDATL);
} |