BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – READ
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 371
' {$PBASIC 2.5}
result VAR Word
DATA Word 1125
READ 0, Word result
DEBUG DEC ? result
This code uses the EEPROM or DATA directive to write the low-byte and
high-byte of the number 1125 into locations 0 and 1 during download.
The BS1 code the uses two READ commands to read each of the bytes out
of EEPROM and reconstructs them into a single word-sized variable.
PBASIC 2.5 uses READ’s optional WORD modifier to read both bytes
from EEPROM and into a word-sized variable. Both programs then
display the value on the screen.
When using PBASIC 2.5, a single READ command can retrieve multiple
bytes and words from sequential EEPROM locations. For example:
' {$PBASIC 2.5}
temp VAR Byte
temp2 VAR Word
READ 25, temp, Word temp2 ' retrieve byte from location 25
' and word from locations 26 and 27
DEBUG DEC temp, CR ' display value of temp, carriage return
DEBUG DEC temp2 ' display value of temp2
Note that the EEPROM and DATA directives store data in the EEPROM
before the program runs, however, the WRITE command can be used to
store data while the program is running. Additionally, the EEPROM
locations can be read an unlimited number of times, but EEPROM
locations can be worn out by excessive writes. See the WRITE command
for more information.
When using the READ and WRITE commands, take care to ensure that
your program doesn’t overwrite itself. On the BS1, location 255 holds the
address of the last instruction in your program. Therefore, your program
can use any space below the address given in location 255. For example, if
location 255 holds the value 100, then your program can use locations 0–99
for data. You can read location 255 at run-time or simply view the
SPECIAL NOTES FOR EEPROM USAGE.
All
2
All
2