Getting Started With PICAXE Microcontrollers
10 11 12 13 14 15 16 17 18
Keyboard 1 2 3 4 5 6 7 8 9 10
4 5 6 7 8 9 10 11 12 13 14 15 16
Our ultimate goal of developing a serial terminal for use with
various microcontroller projects
involves two major functions: we
need to be able to serially transmit
the value of a key-press to our
target project and then receive the
resulting serial transmission from
the target project to the terminal
and display it on the LCD. We are
going to tackle the second function first, because frequently that’s
all that’s required; many projects
simply need a means of displaying
program output on an LCD display.
As was mentioned at the end
of Part 2, we will use a second
microcontroller to test our
terminal. Any controller capable of
five-volt level serial transmission
will do, but we will use the
PICAXE-08M for three reasons:
FIGURE 4. PICAXE-18X Terminal Schematic.
installed on your PC. Also, in the
Editor’s View menu, select Options and
then select the Editor tab. In the
Compiler section, select Enhanced —
this enables several Basic commands
that have been added recently to
PICAXE Basic, and that we will be using
in our programs.
Our first program (KeyboardLCD
.bas) provides an interface between
the keyboard and the LCD. Essentially,
it consists of two parts: a keyboard
scanning routine and the LCD
character display routine. The
latter is similar to the LCD software
discussed in Part 2 of this series, so we
don’t need to discuss it further here.
The keyboard scanning routine, however, does require some explanation.
If you read through the code, you
will see that each of the four outputs is
sequentially raised to a high voltage
level while the other three outputs are
held low. While one output is high, the
software scans the four inputs. These
four inputs are normally held low by
the four resistors shown in Figure 3, so
if one of the inputs is at a high level, it
is because the switch connecting it
58 March 2007
and the currently high output is being
pressed. Since the entire scanning
routine occurs much more rapidly
than a single key-press, the software
can identify which key has been
pressed. The value of the key-press is
then sent to the LCD for display.
As was noted earlier, the 18X
outputs on pins 10-13 are shared by the
keyboard and the LCD. However, when
the keyboard is being scanned, the LCD
enable line is inactive, so the LCD
ignores the changing outputs; when data
is being output to the LCD, the scanning
routine in not operative. As a result, the
shared output pins are not a problem.
Before you download Keyboard
LCD.bas to the 18X, be sure to set the
Editor Options correctly. Select
Options, then Mode and 18X and 256
gosubs, which is necessary because of
the number of “gosub” instructions
we will be using. Under the Serial Port
tab, also select the port you are using.
Then download KeyboardLCD.bas
and test it out; once it is working
properly and you understand how it
functions, you’re ready to move on to
the task of serializing the LCD.
1) It’s amazingly inexpensive (less
2) It uses the same programming
language as the PICAXE-18X, which
simplifies things considerably.
3) It’s the author’s favorite chip in the
The first program we will implement
on the 08M ( Sertxd.bas) is a simple one
— it serially outputs the words “One”
through “Ten” at 2400 baud, with a brief
pause between each word. Both the
08M and the 18X have two different
commands for outputting serial data.
“Serout” is a general-purpose command
that can be used with any output pin
and at several baud rates. “Sertxd” is
much more specific; it only functions
with the programming connection to
the PC, and it is limited to 4800 baud.
The purpose of the Sertxd command is
to provide a simple serial connection to
the PC as an aid in program development and debugging. It is used in
conjunction with the Terminal Window
of the Programming Editor Software.
In order to see how Sertxd.bas