EEPROMs are non-volatile memory devices, and as such retain the data written to it, even when powered-off. They can be used to store small amounts of data like configuration information, fonts, bitmaps, etc. The EEPROM driver provides APIs to read, write and protect an EEPROM.
The EEPROM module functions are declared in eeprom.h
. The following
example stores and updates the reboot count in address location 0
of
the EEPROM.
Reboot Counter.
#include <stdio.h>
#include <stdint.h>
#include <eeprom.h>
#include <lcd.h>
int main()
{
uint8_t reboot_count;
board_init();
lcd_init();
eeprom_init();
board_stdout(LCD_STDOUT);
reboot_count = eeprom_read(0);
reboot_count++;
eeprom_write_protect(0);
eeprom_write(0, reboot_count);
eeprom_write_protect(1);
printf("Reboot Count: %u", reboot_count);
return 0;
}