Skip to content

Instantly share code, notes, and snippets.

@SaheblalBagwan
Last active March 13, 2018 06:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SaheblalBagwan/298475e85839ea9b379bbc2dd9348baf to your computer and use it in GitHub Desktop.
Save SaheblalBagwan/298475e85839ea9b379bbc2dd9348baf to your computer and use it in GitHub Desktop.
void EEPROM_WriteByte(unsigned char eepromAddress, unsigned char eepromData)
{
unsigned char gie_Status;
while(WR); // check the WR bit to see if a previous Write operation is in progress
EEADR=eepromAddress; // Write the address to EEADR.
EEDATA=eepromData; // load the 8-bit data value to be written in the EEDATA register.
WREN=1; // Set the WREN bit to enable eeprom operation.
gie_Status = GIE; // Copy the current Interrupt state
GIE = 0; // Disable the interrupts
EECON2=0x55; // Execute the special instruction sequence
EECON2=0xaa; // Refer the datasheet for more info
WR=1; // Set the WR bit to trigger the eeprom write operation.
GIE = gie_Status; // Restore the interrupts
WREN=0; // Disable the EepromWrite
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment