28 lines
770 B
C++
28 lines
770 B
C++
#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
|