diff --git a/inc/eeprom_rw.h b/inc/eeprom_rw.h new file mode 100644 index 0000000..aef2f8a --- /dev/null +++ b/inc/eeprom_rw.h @@ -0,0 +1,9 @@ +#ifndef _EEPROM_RW_ +#define _EEPROM_RW_ + +#include "stdint.h" + +void eeprom_write(uint8_t addr, uint8_t data); +uint8_t eeprom_read(uint8_t addr); + +#endif \ No newline at end of file diff --git a/src/eeprom_rw.c b/src/eeprom_rw.c new file mode 100644 index 0000000..75ff9ef --- /dev/null +++ b/src/eeprom_rw.c @@ -0,0 +1,34 @@ +#include "BA45F5250.h" +#include "stdint.h" +#include "build-in.h" +#include "eeprom_rw.h" + +void eeprom_write(uint8_t addr, uint8_t data) +{ + _emi = 0; + _eea = addr; + _eed = data; + _mp1l = 0x40; + _mp1h = 0x01; + _iar1 |= 0b00001000; + _iar1 |= 0b00000100; + while(_iar1 & 0b00000100); + _iar1 = 0x00; + _mp1h = 0x00; + _emi = 1; +} + +uint8_t eeprom_read(uint8_t addr) +{ + _emi = 0; + _eea = addr; + _mp1l = 0x40; + _mp1h = 0x01; + _iar1 |= 0b00000010; + _iar1 |= 0b00000001; + while(_iar1 & 0b00000001); + _iar1 = 0x00; + _mp1h = 0x00; + _emi = 1; + return _eed; +} \ No newline at end of file