2
2
e
NOTE: This is written for the BS2
but can be used for the BS2e,
BS2sx and BS2p also. Locate the
proper source code file or modify
the STAMP directive before
downloading to the BS2e, BS2sx or
BS2p.
5: BASIC Stamp Command Reference - DATA
Result
VAR
DATA
word 1125
READ
0, Result.LOWBYTE
READ
1, Result.HIGHBYTE
DEBUG
DEC Result
This code would write the low-byte and high-byte of the number 1125 into
locations 0 and 1 during download. When the program runs, the two
READ commands will read the low-byte and high-byte out of EEPROM
(reconstructing it in a word-size variable) and then display the value on
the screen. See the READ and WRITE commands for more information.
2
2
Demo Program (DATA.bs2)
p
sx
This program stores a number of large text strings into EEPROM with the DATA directive and
then sends them, one character at a time via the DEBUG command.
demonstration of how to save program space by storing large amounts of data in EEPROM
directly, rather than embedding the data into DEBUG commands.
'{$STAMP BS2}
'-----Define variables-----
Index
VAR
PhraseNum VAR
Character
VAR
'-----Define all text phrases (out of order, just for fun!)-----
Text1
DATA "Here is the first part of a large chunk of textual data", CR
DATA "that needs to be transmitted. There's a 12 second delay", CR
DATA "between text paragraphs.", CR, 255
Text3
DATA "The alternative (having multiple DEBUGs or SEROUTs, each", CR
DATA "with their own line of text) consumes MUCH more EEPROM", CR
DATA "(program) space; up to 854 more bytes, in this case!", CR, CR, 255
Text6
DATA "The 255 is used by this program to indicate we've reached the", CR
DATA "End of Text. The Main routine pauses in between each block of", CR
DATA "text, and then uses a LOOKUP command to retrieve the location", CR
DATA "of the next desired block of text to print.", 255
Text4
DATA CLS, "This program also demonstrates retrieving data out of order", CR
DATA "in relation to the way it is stored in EEPROM. Additionally", CR
DATA "control codes (like carriage-returns, clear-screens, etc) can", CR
DATA "be embedded right in the data, as it is here.", CR, CR, 255
Text2
DATA "This is an example of a good way to save space in your", CR
DATA "BASIC Stamp's program by storing data into EEPROM and", CR
DATA "retrieving it, one byte at a time, and transmitting it", CR
DATA "with just a single DEBUG (or SEROUT) command.", CR, CR, 255
Text5
DATA "The PrintIt routine simply takes the Index variable, retrieves", CR
WORD
WORD
'Holds current location number
NIB
'Holds current phrase number
BYTE
'Holds current character to print
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 95
'STAMP directive (specifies a BS2)
This is a good
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?