35 lines
764 B
C
35 lines
764 B
C
|
|
|
|
#include <stdint.h>
|
|
#include <avr/io.h>
|
|
|
|
#include <eeprom.h>
|
|
#include <tool.h>
|
|
|
|
void eeprom_write_byte(uint16_t address, uint8_t byte) {
|
|
while (EECR & BIT(EEPE));
|
|
EEAR = address;
|
|
EEDR = byte;
|
|
REG_SETUP_BIT(EECR, EEMPE);
|
|
REG_SETUP_BIT(EECR, EEPE);
|
|
}
|
|
|
|
uint8_t eeprom_read_byte(uint16_t address) {
|
|
while (EECR & BIT(EEPE));
|
|
EEAR = address;
|
|
REG_SETUP_BIT(EECR, EERE);
|
|
return EEDR;
|
|
}
|
|
|
|
void eeprom_write_bytes(uint16_t address, uint8_t* data, uint16_t size) {
|
|
for (uint16_t i = 0; i < size; i++) {
|
|
eeprom_write_byte(address + i, data[i]);
|
|
}
|
|
}
|
|
|
|
void eeprom_read_bytes(uint16_t address, uint8_t* data, uint16_t size) {
|
|
for (uint16_t i = 0; i < size; i++) {
|
|
data[i] = eeprom_read_byte(address + i);
|
|
}
|
|
}
|