Created
January 16, 2011 00:18
-
-
Save PhirePhly/781405 to your computer and use it in GitHub Desktop.
AVR EEPROM Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank You!!!:D