PICAXE PRIMER
■ FIGURE 10. PNP and NPN switching circuits (Version 2).
■ FIGURE 9. PNP and NPN switching circuits (Version 1).
• Make It Fast — In our earlier
experiment with the two discrete
LEDs, we discovered that we needed
to switch the LEDs at a rate greater
than 50 Hz in order to avoid seeing
any flickering, so our main
multiplexing loop must be able to
execute at least 50 times per
second. Another way to say the
same thing is that the loop can't take
more than 20 ms per iteration.
to discussing the details of the
program.
As we've done in the past, the
number of each of the following
comments refers to the
corresponding number in brackets at
the right-hand edge of the program
listing.
• Keep It Balanced — The
portion of the code that lights the
ten's digit should execute in the
same amount of time as the portion
of the code that lights the one's
digit. If the timings aren't equal, one
displayed digit will appear brighter
than the other.
(
LEDmultiCount99.bas) is available
for download at the article link. We
still need to discuss how the
program implements the three
points listed above, but I'm sure you
will want to run the program first.
When you download
LEDmultiCount99.bas to your
breadboard setup, the display should
repetitively count up from 00 to 99
at a rate of one count per second. If
not, you will need to check the
wiring on your breadboard.
When you're sure your system is
working correctly, we can move on
1) I think we've discussed the
time variable in a previous
installment, but in case I'm
mistaken, let me explain.
Time is a built-in word
variable that's available in all
• Avoid Ghosting — We need to
make sure that we never change the
data that's being output on port B
while something is being displayed
on the LEDs. If we were to do that,
some of the display segments that
should be off would appear to be
faintly lit — a phenomenon known as
ghosting.
Our multiplexing program
■ FIGURE 11. Breadboard setup for multiplexing experiment.
February 2013 55