N and V column

Column #120: You Can’t Touch That: Non-contact Access Control
Page 70 The Nuts and Volts of BASIC Stamps (Volume 6)
Scratchpad as a serial buffer. The first thing we have to do, though, is setup the program so
that the compiler can detect a BS2p or BS2pe and create a symbol to that effect.
#DEFINE __No_SPRAM = ($STAMP < BS2P)
With this definition the symbol called __No_SPRAM will be set to True if we're not using a
BS2p or BS2pe – hence are forced to define a buffer in our variable RAM space. Let's get to
that:
#IF __No_SPRAM #THEN
buf VAR Byte(10)
#ELSE
chkChar VAR Byte
#ENDIF
Remember that conditional compilation is just that: conditional, and it means that what
actually gets compiled and downloaded will change based on the BASIC Stamp module we're
using. In the code above, the array called buf is only created when using a BS2, BS2e, or
BS2sx. When using a BS2p or BS2pe, we create a variable called chkChar.
And now to the core of the program. What you'll realize is that no matter which BS2-family
module we use, receiving the RFID tag string in this program is much easier here than with
the BS1. The only question is where those bytes will be stored, and that is determined by the
module in use.
Main:
LOW Enable
#IF __No_SPRAM #THEN
SERIN RX, T2400, [WAIT($0A), STR buf\10
#ELSE
SERIN RX, T2400, [WAIT($0A), SPSTR 10]
#ENDIF
HIGH Enable
When we're using a BS2, BS2e, or BS2sx the tag string is stored in our variable buffer,
otherwise it gets stuffed into the first 10 bytes of the Scratchpad. But see how much easier
this is? The STR and SPSTR modifiers are huge timesavers here.
With the tag string in RAM, we can compare it against the table, and again, it's much easier
with the BS2-family.