Skip to content

Instantly share code, notes, and snippets.

@PhirePhly
Created January 16, 2011 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhirePhly/781405 to your computer and use it in GitHub Desktop.
Save PhirePhly/781405 to your computer and use it in GitHub Desktop.
AVR EEPROM Library
// Kenneth Finnegan, 2011 - GPLv2
// kennethfinnegan.blogspot.com
// Read a single byte from the given address
unsigned char EEPROM_read( unsigned int eeprom_addr ) {
// Spin-lock until EEPROM finishes prev write
while (EECR & (1<<EEPE)) ;
// Setup address register
EEAR = eeprom_addr;
// Start read
EECR |= (1<<EERE);
// Finishes right away
return EEDR;
}
// Write a single byte to the given address
// Duplicate checking, no error checking.
void EEPROM_write (unsigned int eeprom_addr, unsigned char eeprom_data) {
// Save a needless write and spinlock on busy EEPROM
if (eeprom_data == EEPROM_read(eeprom_addr))
return;
// Setup addr and data registers
EEAR = eeprom_addr;
EEDR = eeprom_data;
// Enable EEPROM write
EECR |= (1<<EEMPE);
// Start EEPROM write
EECR |= (1<<EEPE);
}
@ArunEmbedded
Copy link

Thank You!!!:D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment