July 2015 13
SHARPENING YOUR TOOLS OF CREATIVITY
Post comments on this article and find any associated files and/or downloads at
connected to anything, so pin B. 7
can be used for any purpose you
want without creating an electrical
problem; third, don’t forget to install
the short bare jumper that connects
the RxD pin on the PL2303HX to pin
C.0 on the 20M2.
The software for our first
experiment this month (hserin20M2.
bas) is available for downloading
at the article link. Now would be a
good time to download it, along with
the other programs we will be using
this month. If you read through the
program listing for the hserin20M2.
bas program, you will see that — aside
from the fact we’re using a different
processor — there are two minor
differences from the hserinFromPC.
bas program that we used in the
First, the pin assignments for the
RxPin and the TxPin have changed.
On the 20M2 processor, the hserin
pin is pin B. 6, and the hserout pin is
pin C.0. We aren’t using the hserout
command in our first experiment, but
we will in our second experiment.
Using pin C.0 for the serout
command will enable us to use the
same hardware setup for the next
experiment, as well.
The second difference has to do
with the “undocumented A.0 pin” on
the 20M2 processor. We’ve already
discussed this issue (in the February
2012 Primer), so I’ll just briefly re-state
it at this point. The PICAXE compiler
recognizes A.0 as an undocumented
name for the Serial Out pin on the
20M2 processor, and accepts a few
undocumented “pseudo” commands,
including high A.0, low A.0, toggle
A.0, and serout A.0. Unfortunately,
it’s not possible to define a name for
the undocumented A.0 pin: including
a symbol LED = A.0 statement in a
program produces a syntax error.
However, whenever we want to
blink the LED on the 20M2 Serial Out
pin, we can just use a combination
of high A.0 and low A.0 commands
(with suitable pauses), or even a
toggle A.0 command. (As we’ll soon
see, the same approach also works
with the 20X2 processor.)
With the above information
in mind, let’s replicate Experiment
4 from the last Primer. This time,
however, we’re using a 20M2
processor. You may want to
refer back to the previous Primer
installment for the details of setting
up the experiment and your terminal
When you’re ready to proceed,
use Figures 1 and 2 to assemble your
breadboard circuit, and download
the hserin20M2.bas program to the
20M2. The results you obtain by
typing one or two characters into the
terminal program should be the same
as last time.
Experiment 2: Adding
hserout, and Speeding
In our previous hardware serial
experiments with the 08M2, we
weren’t able to use the hserout
command. As I explained then,
on both the 08M2 and 14M2, the
hserout command is only available
on the processor’s Serial Out pin
(C.0 on the 08M2, and B.0 on the
14M2). As a result, if we were to use
the hserout command, every time we
downloaded a new program to the
processor we would also be sending
“garbage” characters out to the PC. In
order to avoid that problem, we used
the serout command with pin C. 2 on
Fortunately, on both the 20M2
and 20X2 processors, the hserout pin
does not conflict with the Serial Out
pin. On both 20-pin processors, the
hserout pin is pin C.0 and the hserin
pin is pin B. 6, which means that we’re
now free to experiment with the
hserout command and speed things
up a bit.
Figure 3 presents the valid serial
baud rates for hardware serial I/O,
along with the baud rates that are
supported by the Cool Term program.
(If you’re using a different terminal
program, you will need to check your
documentation for the valid baud
For each baud rate, the entries in
the middle column of Figure 3 show
the required value for the baud_setup
parameter of the hsersetup command.
The “X” in each entry must be
replaced by the appropriate value (in
MHz) for the clock speed at which
the PICAXE processor is running.
n FIGURE 2. Breadboard setup for Experiments 1-4.