Specifications
BASIC Stamp II
Page 340 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
name DATA (n)
This directive allocates n bytes of EEPROM starting at the address name
and extending to address name + (n-1). If you restrict Writes to this
range of addresses, you’ll be fine. If your program grows to the point
that it overlaps the addresses allocated, the STAMP2 host program will
generate an error message and refuse to download it. See the section
BS2 EEPROM Data Storage for more information on the Data
directive.
Demo Program
This program is the bare framework of a data logger—an application
that gathers data and stores it in memory for later retrieval. To provide
sample data, connect the circuit of figure I-14a (see RCtime) to pin 7.
Use a 10k resistor and 0.1µF capacitor. Run the program and twiddle
the pot to vary the input data. The program writes the data to EEPROM
at 1-second intervals, then reads it back from the EEPROM. If you plan
to use Write in a similar application, pay close attention to the way the
program allocates the EEPROM with Data and uses constants to keep
track of the beginning and ending addresses of the EEPROM space.
Note that this program uses an unnecessarily large variable (a word)
for the EEPROM address. With only 10 samples and with EEPROM
addresses that start at 0, we could have gotten away with just a nibble.
However, real-world applications could expand to hundreds of
samples, or be located much higher in EEPROM, so we used a word
variable to set a good example.
result var word ' Word variable for RCtime result.
EEaddr var word ' Address of EEPROM storage
locations.
samples con 10 ' Number of samples to get.
log data (samples) ' Set aside EEPROM for samples.
endLog con log+samples-1 ' End of allocated EEPROM.
for EEaddr = log to endLog' Store each sample in EEPROM.
high 7: pause 1 ' Charge the cap.
rctime 7,1,result ' Measure resistance.
result = result*42/100 ' Scale to fit one byte (0-255)
debug "Storing ", dec result,tab," at ", dec EEaddr,cr
WRITE EEaddr,result ' Store it in EEPROM
pause 1000 ' Wait a second.
next ' Do until all samples done.










