下面是MCC生成的代码。
void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData)
{
uint8_t GIEBitValue = INTCONbits.GIE;
//Set NVMADR with the target word address: 0x310000 - 0x3103FF
NVMADRU = 0x31;
NVMADRH = (uint8_t)((bAdd & 0xFF00) >> 8);
NVMADRL = (uint8_t)(bAdd & 0x00FF);
//Load NVMDATL with desired byte
NVMDATL = (uint8_t)(bData & 0xFF);
//Enable NVM access
NVMCON0bits.NVMEN = 1;
//Disable interrupts
INTCONbits.GIE = 0;
//Perform the unlock sequence
NVMCON2 = 0x55;
NVMCON2 = 0xAA;
//Start DATAEE write and wait for the operation to complete
NVMCON1bits.WR = 1;
while (NVMCON1bits.WR);
//Restore all the interrupts
INTCONbits.GIE = GIEBitValue;
//Disable NVM access
NVMCON0bits.NVMEN = 0;
}
|