|
|
EEPROM is Electrically erasable programmable ROM.Thus on storing any data or program on eeprom does not get lost even after the power is turned of as in case of static RAM.
Atmega32 has 1024 bytes of EEPROM and has a durability of 100,000 write cylces and infinte read cycles.
My program is based on an excellent tutorial i found on AVR freak which is here.
It is a very straightforward implementation of the tutotrial on avr freaks.
Writing to EEPROM is done either in bytes, words or blocks.
Writing in bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define F_CPU 16000000UL | |
#include <avr/io.h> | |
#include <avr/eeprom.h> | |
#include <util/delay.h> | |
#include <stdio.h> | |
#include "LCD.h" | |
int main() | |
{ | |
lcd_init(); | |
uint8_t ByteOfData = 12; | |
eeprom_write_byte((uint8_t*)46,51); | |
ByteOfData = eeprom_read_byte((uint8_t*)46); | |
_delay_ms(10); | |
lcd_char((char)ByteOfData); | |
return 0; | |
} |
Similarly writing a string to EEPROM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define F_CPU 16000000UL | |
#include <avr/io.h> | |
#include <avr/eeprom.h> | |
#include <util/delay.h> | |
#include <stdio.h> | |
#include "LCD.h" | |
int main() | |
{ | |
char stringOfData[6]; | |
char stringOfReadData[6]; | |
lcd_init(); | |
sprintf(stringOfData,"hello"); | |
eeprom_write_block((const void*)1,&stringOfData,6); | |
eeprom_read_block(&stringOfReadData,(const void*)1,4); | |
_delay_ms(10); | |
lcd_string_array((char *)stringOfData); | |
return 0; | |
} |
3 comments:
I think you just printed the original variable on the LCD.
lcd_string_array((char *)stringOfData);
instead of
lcd_string_array((char *)stringOfReadData);
you meant to print the read variable from EEPROM right?
update function works fine in main loop but within while with a if condition, its not working....
Thanks for your nice tutorial....
Post a Comment