Eeprom Read/Write

SD70M

Senior Member
Hi all,

Newbie here so please be gentle.

Just a quick question which I think I'll have trouble phrasing but here goes (using an anolgy)

Chip: 20M2, Program: to light 1 led and remember state when power is disconnected and then connected again.

Am I right in the following:

1. power up circuit
2. change the state of the led and save that state to eeprom 0, ? (where ? is the state of 0 or 1)
3. power down circuit
4. power up circuit
5. get state from eeprom 0 and then wait for change of state, etc?

Would that be correct?

Angie
 

Jamster

Senior Member
Welcome to the Forum!
Yes that would be correct, you will need the "write" and "read" commands (found in manual 2)

Jamster
 

SD70M

Senior Member
Thanks Jamster

So glad someone pointed me in the direction of Picaxe.

So moving on from that, can I :

1. download a prog that puts default values into the eeprom
2. download another program which uses those values

or does downloading the new prog clear the eeprom?

Angie
 

hippy

Technical Support
Staff member
@ SD70M : The choice is yours ( for many but not all PICAXE ).

If you add #NO_DATA ( or #NO_TABLE ) to your program then the Eeprom on chip will not get updated by a download. What was previously stored will still be there when your program runs after a download.

If you don't have #NO_DATA ( and no #NO_TABLE ) if you use EEPROM commands then those values will be set as instructed by the EEPROM commands at download, and the rest will be zeroed.
 

SD70M

Senior Member
Thanks Hippy

I saw the #no_data directive but wasn't sure if it was only recognised on a power up , rather than a new program download.

This is great as I can remove the if...then statements regarding min and max values in eeprom.

Thankyou again

Angie
 

mrburnette

Senior Member
Am I right in the following:

1. power up circuit
2. change the state of the led and save that state to eeprom 0, ? (where ? is the state of 0 or 1)
3. power down circuit
4. power up circuit
5. get state from eeprom 0 and then wait for change of state, etc?

Would that be correct?

Angie
If things were more complicated, say you wanted to save the brightness or pulse rate which was any non-zero value, then a simple change in logic affords more flexibility. For example
1b. Check eeprom address to see if led is active, that is <> 0
1c. If 1b is true, read eeprom address and initialize led variable value
2....

In this way, the very first time the program is run, you will initialize led to default value - if = 0 then led is off but if default is non-zero or a value from a previous "save" you will have that value initialized. Then steps 4 becomes step 1 and step 5 is incorporated in 1a and 1b. Now we have a situation where if the eeprom value =0 then this can represent "off" but any value from 1 - 255 can represent brightness or pulse rate, etc.

- Ray
 
Top