Files
the-waterinator/firmware/atmega/source/eeprom.c
T
2025-10-01 15:34:11 +02:00

26 lines
516 B
C

#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
uint8_t eepromRead(uint8_t address) {
// wait for previous write
while (EECR & (1 << EEPE));
//read from address
EEAR = address;
return EECR |= (1 << EERE);
}
void eepromWrite(uint8_t address, uint8_t data) {
// wait for previous write
while (EECR & (1 << EEPE));
if (eepromRead(address) != data) {
EEAR = address;
EEDR = data;
EECR |= (1 << EEMPE);
EECR |= (1 << EEPE);
}
}