Datasheet

Page 42ยท Applied Robotics with the SumoBot
As the SumoBot programs get larger and more complex, both good EEPROM
management and strict adherence to code conventions will make large and complex
programs seem easy, or at least, not nearly as hard as they might look.
ACTIVITY #1: A CLOSER LOOK AT THE EEPROM
The optional Symbol names that you can use to precede DATA directives are powerful
programming tools that make storing and accessing values much easier. Especially when
you're dealing with more than one list of stored values,
Symbol names are indispensable.
This activity starts by examining the relationship between a
DATA directive's Symbol
name and the values the
DATA directive pre-writes to EEPROM when the program
downloads.
This activity also introduces techniques you can use to store new values in an EEPROM
byte to track how many times the Reset button has been pressed and released. In
addition, distinguishing between odd and even values as well as odd and even numbers of
resets is introduced.
Symbol Names, Addresses, and EEPROM Bytes
The BASIC Stamp 2's EEPROM is 2048 bytes. Each byte has an address that can store
either program tokens or values you tell it to store. When a program is downloaded to
EEPROM, it occupies the highest addresses, starting at address 2047, 2046, 2045, etc. If
a program is 500 bytes, it will occupy memory from EEPROM addresses 2047 to 1548.
That leaves EEPROM addresses 0 to 1547 free for storing data.
You can use
DATA directives to pre-store values in available EEPROM bytes (those not
being used for program storage) at the time a program is downloaded. Once the program
is running, EEPROM bytes are not like variables in that they cannot be manipulated
directly, but
READ commands can copy values stored in EEPROM to variables. After the
values are copied to variables, they can be manipulated, used for comparisons, etc, and
then
WRITE commands can copy the values stored in those variables back to EEPROM.
The program SymbolNamesVsAddressContents.bs2 declares several
DATA directives:
Numbers DATA 7, 20, 11, 2, 80
RunStatus DATA 0
UndefData DATA (20)
Alphabet DATA "ABCDEFG"