Intial commit
This commit is contained in:
28
src/eeprom.cpp
Normal file
28
src/eeprom.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "eeprom.h"
|
||||
|
||||
namespace eeprom
|
||||
{
|
||||
void write(uint8_t address, uint8_t data) {
|
||||
/* Wait for completion of previous write */
|
||||
while(EECR & (1<<EEWE));
|
||||
/* Set up address and data registers */
|
||||
EEAR = address;
|
||||
EEDR = data;
|
||||
/* Write logical one to EEMWE */
|
||||
EECR |= (1<<EEMWE);
|
||||
/* Start eeprom write by setting EEWE */
|
||||
EECR |= (1<<EEWE);
|
||||
}
|
||||
|
||||
uint8_t read(uint8_t address) {
|
||||
/* Wait for completion of previous write */
|
||||
while(EECR & (1<<EEWE));
|
||||
/* Set up address register */
|
||||
EEAR = address;
|
||||
/* Start eeprom read by writing EERE */
|
||||
EECR |= (1<<EERE);
|
||||
/* Return data from data register */
|
||||
return EEDR;
|
||||
}
|
||||
|
||||
} // namespace eeprom
|
||||
Reference in New Issue
Block a user