by Jon Williams
Putting the Spotlight on BASIC Stamp Projects, Hints, and Tips
Timing Is Everything
The dreaded “I” word ... yes,
everybody talks about it ... there’s
lots of bloviating about it ... but
what can we actually do with inter-
rupts? Well, quite a lot, actually —
if we’re patient and work carefully.
Thankfully, SX/B makes interrupt
programming more manageable
than we thought it could be.
It wasn’t very long after the BASIC Stamp and other
BASIC language microcontrollers appeared that
advanced users started asking about using interrupts.
Well, neither the BASIC Stamp family nor — to my knowledge — any of the micros in the same class supports true
interrupts; it’s just not practical in Basic and I’m about to
explain why. Please, please, please ... don’t fill my Email
basket with flame mail telling me that your favorite Basic
language controller does do interrupts; let me qualify my
Let’s back up a bit for those who may be a bit new.
An interrupt is just that: an event or condition that
suspends (interrupts) a program, forces the code into a
special section (usually called an ISR, for Interrupt
Service Routine), then goes back to what it was doing
when the interrupt occurred. Sounds pretty simple and
straightforward, right? Well, not quite.
Here’s why the BASIC Stamp and similar microcon-
trollers don’t support true interrupts (as I just described):
What happens if we’re doing a bit-bang serial input (as
most micros in the BASIC Stamp class do) and we get an
interrupt? Well, if we process the interrupt, our serial
timing is going to get trashed and we will corrupt the data
— this could lead to a very big problem. The same problem holds true for any time-oriented function — things like
SERIN, SEROUT, PULSIN, PULSOUT, PAUSE, OWIN,
OWOUT, etc. You get the idea.
How is this handled, then? Well, the BS2p family has
the ability to do what is called “pin polling.” When
enabled, the BASIC Stamp 2p will check pin states in
between high level instructions and act in accordance
with the polling set up configuration (there are several
options). This pseudo-interrupt process can be very
useful. Now, I realize that some Basic language micro-controllers use hardware UARTs and timers and this
does help alleviate the interrupt issue I just described.
That said, the use of internal hardware occasionally
limits design flexibility as specific I/O points on the
micro are required. I’m not saying that any of this is bad
... it just is.
Give Me an “I”
NUTS & VOLTS
Figure 1. Serial data byte structure.
Okay, now that you know why the BASIC Stamp
doesn’t support true interrupts, what about SX/B? For
those of you who have checked it out, you’ve no doubt
seen that there is indeed interrupt support. Yes, I’m going
to show you how to use one type of interrupt this month
— and to do two things with it: receive and buffer serial
data (coming from a BASIC Stamp host) and to multiplex
an eight-digit, seven-segment LED display.
The warnings I gave about interrupts above apply to
SX/B — the difference is that SX/B allows interrupts any
time you configure them. So, if you’re going to be using
interrupts in an SX/B program, you should not be using
any of the time oriented functions I mentioned earlier
(note that SX/B does not have the one-wire commands of
As this is going to be a bit of a ride, let’s get right to
it. I was in my favorite store the other day (yes, Tanner
Electronics in Dallas, TX) and found a surplus eight-digit, seven-segment LED display that cost $1.00; that’s