Datasheet
Chapter 2: EEPROM Tricks and Program Tips · Page 47
√ Modify the RunStatus DATA directive like this:
RunStatus DATA @10, Word 500
√ Modify the command that reads the EEPROM byte at the RunStatus address
like this:
READ RunStatus, Word temp
√ Test the program to make sure it can retrieve and display 500.
√ Check the Memory Map and verify that the
RunStatus DATA directive sets
aside 2 bytes instead of 1.
Changing EEPROM Values Between Resets
Let's take a closer look at how an EEPROM byte can be used to track the number of
times the SumoBot's Reset button has been pressed and released. This technique can also
be applied to counting the number of times the power to the BASIC Stamp has been
turned off and back on. You can just as easily insert the
READ and WRITE commands
from the next example program into an
IF...THEN statement and count sensor events.
EEPROM is not a replacement for RAM. EEPROM bytes can certainly be used to store
values, count events, and so on. However, the EEPROM on the BASIC Stamp 2 is limited
to 10-million rewrites. In contrast, variables, which reference values stored in the BASIC
Stamp's RAM memory, do not have a limitation on the number of times you can rewrite the
values they store.
If your BASIC Stamp modifies a single byte in EEPROM once a minute, that EEPROM byte
will wear out in between 19 and 20 years. At once per second, the EEPROM byte will wear
out in around 4 months.
This
EepromCounter DATA directive from the next example program stores a 0 to an
EEPROM byte when the program is downloaded. The
Symbol name EepromCounter
becomes a constant for the address of that byte.
EepromCounter DATA 0
A byte variable will be used to manipulate a copy of the EEPROM value.
temp VAR Byte
The program can then use the READ command to fetch the value stored in the EEPROM
byte whose address is
EepromCounter, and copy it to the temp variable.