immediately whenever a serial byte
has been received (i.e., whenever the
hserflag is automatically set to 1), the
complete command we need is "set
intflags %00100000, %00100000.”
Similarly to the setint command
discussed earlier, the second parameter
(mask) says "just check bit5 of the flags
(hserflag) and ignore all the others"
and the first parameter (flags) says
"whenever bit5 (hserflag) is high, execute
the interrupt code." I know this has
been a considerable amount of detail
to wade through, but these are powerful commands and worth the effort.
Now let's turn our attention to the
Hserin TestInt.bas program that you
downloaded earlier to see how we
are going to implement our interrupt.
The main program is very similar to that
of the Hserin TestAll.bas that we worked
with earlier. The first major difference
is the "setintflags" command that we
just discussed. Once that command
is executed, the remainder of the main
program is an infinite "do...loop" that
simply blinks an LED interminably.
Next, we have the interrupt subroutine
that, as you can see, is actually much
simpler than the GetNewData
subroutine of the earlier program.
We don't need to use pointers at
all (because the interrupt only
processes one received byte at a
time) and the received byte is always
stored in location 0 (because we
reset the scratchpad variables each
time before exiting the interrupt
routine), which means that we can
again use a simple "get" statement to
retrieve the byte each time. Finally,
before exiting the interrupt routine,
we re-enable the interrupt so that the
next byte will also be captured. The
only other aspect of the program that
requires explanation is the "myDelay"
subroutine. I know it looks a little
strange, and you're probably wondering
why I didn't just use a "pause 500"
command after the "high LED" and
"low LED" commands in the main
loop. In fact, that's exactly what I did
do in my first attempt at this program.
The documentation for the
setintflags command states that the
"flags byte is checked between
execution of each command line in the
program, between each note of a tune
20
February 2009
command, and continuously during any
pause command" so I assumed that a
pause command (but not a wait
command) should work fine.
However, with "pause 500" in each
of those places, the LED blinked so
rapidly that it appeared as if the
pause commands were being ignored.
I finally figured out what was
happening. Apparently, each time that
the program was interrupted it didn't
resume execution in the middle of the
interrupted pause command; rather,
it went on to the next command in
the program, effectively truncating
each pause and blinking the LED at a
much too rapid pace. The solution of
replacing each longer pause with a
loop of much shorter pauses restored
the LED's sanity, which supports my
original interpretation of the problem.
Download the Hserin TestInt.bas
program to the 28X1 (the two IRMB
programs remain the same) and try it;
since the interrupt subroutine executes
so quickly, this approach solves the
problem of the occasional missing bytes
that we saw earlier. The "pause 100"
command in the IRMB_Serout.bas
program slows things down more
than enough for the interrupt routine
to keep up with the data rate.
You may want to experiment
with shortening that pause, but when
I tried to do so I began to get some
transmission errors. However, I think
that the errors were caused by
IRMBserin.bas not being able to keep
up, not by the 28X1's interrupt
routine. In any case, the current rate
of transmission seems fast enough
and is reliable at a distance of at least
20 feet, so I consider it adequate for
my purposes. As you can see, the IR
Multi-Board provides a powerful and
flexible modular approach to the
design of IR-based I/O circuits. Once
we have covered several of the other
devices on our list of I/O modules for
our Master Processor board, we'll
probably find a use for the IRMB in
our Data Collection system. In the
meantime, I'm sure you will also find
the IRMB to be a helpful addition to
some of your own projects. If you
develop an interesting IRMB
application, I would love to hear
about it.
LET'S TAKE A BREAK!
The IR Multi-Board turned out to be
more powerful that I realized it would
be when I first began its development,
but the explanations of the IRMB's
various functions also have become
more involved than I anticipated at
the start of this three-part series.
We've all been working fairly hard and
we deserve a break! So, in the next
installment of the Primer we're going
to turn our attention to interfacing
our Master Processor with various
inexpensive LCD displays based on the
Hitachi HD44780 controller (for more
info, see "Getting Started with PICAXE
Microcontrollers, Part 2" in the
February 2007 issue of Nuts & Volts).
These displays are easy to work with
and they can be extremely helpful in a
variety of projects. We will be focusing
on four specific Hantronix displays (see
Figure 2) that I have chosen because
they are inexpensive (ranging from $5
to $10) and have pinouts that are fairly
easy to adapt to the construction of
stripboard circuits. All of them are available at www.Mouser.com; go to their
site and enter the Hantronix part number
from Figure 2 to get pricing information and to download the datasheets.
We will be developing two types
of stripboard circuits for each of the
display sizes (16x2 and 8x2). Our first
stripboard projects will simplify the
interface between our Master Processor
board and the parallel displays and our
second approach will use a PICAXE-
14M to convert the parallel displays
to stand-alone serial peripherals for
use with our Master Processor (or
any other project you may have in
mind). You may already have one or
two small HD44780-based displays
on hand that will also work with the
circuits we will be developing.
For the 16x2 displays, the main
requirement is that the 14 or 16 pin
connector be along the top of the board.
This arrangement makes the stripboard
layout much simpler than what is required
to accommodate a connector on the
bottom edge of the display. So, before
the next installment of the Primer arrives,
you may want to round up a couple of
suitable LCD displays and stripboards
for our upcoming projects.
NV