Getting Started With PICAXE Microcontrollers
functions, we first need to construct a
simple PICAXE-08M circuit (either in an
empty space on the Terminal breadboard or on a second small breadboard).
Figure 5 presents the schematic for this
circuit, which is simply the PICAXE-08M
programming circuit. Because we are
transmitting data back to the PC on the
programming connector’s Serial Out line
(pin 7), no additional connections to the
08M are necessary.
If you have a second serial port
available on your PC, you can use two
serial connections at the same time
without having to move your three-pin
programming adapter back and forth
between the 08M circuit and the 18X
circuit. Simply construct a second three-pin adapter, connect it between the
08M circuit of Figure 5 and your PC, and
you are ready to download Sertxd.bas to
the PICAXE-08M. If you only have one
available serial port, you will have to
“cable swap” whenever you switch
between downloading the 08M software
and the 18X software, or vice versa.
When you have constructed the
circuit of Figure 5 and have Sertxd.bas
open in the Programming Editor, make
sure you have the Options set for the
PICAXE-08M and the correct serial port.
Also, in the Editor’s View menu, select
Options and then select the Editor tab.
In the Serial Terminal section, check the
“Automatically open Serial Terminal
after download” option, so you will be
able to view the serial output from the
PICAXE-08M. Download Sertxd.bas to
the 08M; you should see the words
“One” through “Ten” repetitively
displayed in the Terminal Window. If
you get an error message, recheck the
Option settings and try again.
Once Sertxd.bas is working properly on the 08M, we’re ready to modify it to output the data from output 4
(pin 3) on the 08M to the one remaining input on the 18X (input 2 on pin 1).
The only changes we need to make in
the Sertxd program are to replace the
first Sertxd command with “Serout 4,
N2400 (outchar)” (which transmits our
serial data on output 4 at 2400 baud)
and to remove the second Sertxd command [Sertxd (cr,lf)]. You may want to
save the new file as Serout.bas, so you
have both of them to experiment with.
In case you were wondering, “cr”
stands for “carriage return” and “lf”
stands for “line feed;” both definitions
are built into PICAXE Basic, but I don’t
think they are documented — I stumbled
across them accidentally! If the Serout
syntax is confusing, read through the
documentation in Part 2 of the PICAXE
manual; it should help clarify things.
To connect the 08M and the 18X,
just disconnect the power from both
circuits and add a jumper wire from
output 4 (pin 3) on the 08M to input
2 (pin 1) on the 18X. If your two
circuits are on separate breadboards,
it is also necessary to connect the
grounds of both breadboards with a
second jumper wire.
On the 18X, the SerinLCD.bas
program will receive the 08M’s serial
transmission and display it on the
LCD. In effect, a PICAXE-18X with
SerinLCD.bas loaded into its program
memory converts any HD44780 LCD
into a serial LCD for use in your projects. In addition, you can easily modify the program to include additional
features you find useful. You could
also construct a complete circuit on a
stripboard the same size as the LCD
and attach it to the LCD board to
make your own serial LCD module.
Of course, the characters displayed
on the LCD by SerinLCD.bas are specific to the keyboard being used, so
they may not be appropriate for your
keyboard. To correct this, locate the
branch statement in SerinLCD.bas and
replace the data characters with ones
that match your keyboard.
Now that we have the two circuits
connected, it’s time to download the
software and test the system. First, set
up the options in the Programming
Editor for the 18X circuit; make sure
you have set the correct serial port on
the PC. Download SerinLCD.bas to
the 18X, change the Option settings
(and your programming cable if you
are using only one), and download
Serout.bas to the 08M. After a brief
pause, the words “One” through “Ten”
should be sequentially displayed on
the LCD, along with an annoying beep
for each word. If not, you will need
to troubleshoot the system, which is
getting a little complex by now!
Implementing the
Complete I/O Terminal
At this point, we are ready to
begin working on our stand-alone
data terminal. First, we need to power-down both circuits again and add one
more jumper wire connecting output
0 (pin 6) on the 18X to input 2 (pin 5)
on the 08M. This connection will
provide for serial output from the
Terminal to the Target. It’s a good idea
to include a 1K resistor in series in this
connection; pin 5 on the 08M is a bidirectional I/O pin, so it’s possible for
it to be accidentally set to be an output pin. The direct connection of two
output pins (with no current-limiting
resistor) can result in a high-level out-
FIGURE 5. PICAXE-08M “ Sertxd.bas” Schematic.
R3 220
1
6
serout
2
+ 5 V
1
8
Gnd
7
RS-232
DB- 9
8
serin
R2 22K
3
2
Picaxe
08M
7
4
R1
3
6
9
5
10K
4
5
March 2007 59