EEPROM

EEPROM

Writing information into EEPROM

EEPROM memory starts from 1 up to 254 addresses (comparable to, 254 elements array)

Write information into EEPROM
main(){ while(1){ EEPROM(WRITE, 3, 238); // write number 238 to eeprom memory address number 3 (out of possible 254) Delay(100); } }

Reading information from EEPROM

Read and store data into variable from EEPROM specific memory place:

Reading data from EEPROM
new data; main(){ EEPROM(READ, 3, data); //read and store data into variable named 'data' from EEPROM specific memory address while(1){ Delay(1000); } }

Saving vital information before going to sleep

Every time micro controller goes to sleep and wakes up - it will restart the code and reinitialize all of your variables. Therefore, in order to save previous variables that are essential for you to keep - save them into EEPROM and restore them at the beginning of the code. For such event we have created callback which can be used to save information just before going to sleep. Callback "detects" that micro controller is going to sleep in 20 seconds and allows user to do quick changes (amongst them is saving essential information into EEPROM):

Using callback and saving information before going to sleep
new data1; new data2; forward saveMyData(); public callback (event) { switch(event) { case GoToSleep: //20 seconds before going to sleep, this callback will be called. { saveMyData(); //function or action to do before going to sleep. In this case - we're saving vital information to EEPROM } } } main(){ EEPROM(READ, 1, data1); //restore previous information EEPROM(READ, 2, data2); //restore previous information for(new i; i<10; i++) { data1 = data1+1; data2 = data2+2; } while(1){ Delay(100); } } saveMyData(){ EEPROM(WRITE, 1, data1); // write data to eeprom memory address number 1 (out of possible 254) EEPROM(WRITE, 2, data2); // write data to eeprom memory address number 2 (out of possible 254) }

Rewriting memory

Keep in mind, if data is saved more than once at the same memory place, previously written data will be erased and new information will be stored.

Rewritnig memory
main(){ while(1){ EEPROM(WRITE, 3, 238); // write number 238 to eeprom memory address number 3 EEPROM(WRITE, 3, 5464); // write over old data (number 238) into new data (number 5464) Delay(100); } }

Erasing all user defined EEPROM memory

To erase whole EEPROM memory use flowing example:

Erasing memory
main(){ EEPROM(WRITE, 3, 238); // write number 238 to EEPROM memory address number 3 EEPROM(ERASE); // erase all EEPROM memory while(1){ Delay(100); } }