character you want. For example, if you look at the fourth
line of the character box (offset row value 3); the byte to the
right shows hex $10 or binary %00010000. This makes the
fifth block solid black, but the rest of the row clear. The next
line sets two blocks black, by using hex byte $18 or binary
%00011000, and the rest you can see in Figure 1. By
setting these bits and storing the data in the LCD’s
character memory, we have established a new custom
character that the software can call.
This doesn’t stop us from displaying standard, single-line words on the LCD screen. It does, however, allow us
to also create large digits that span all four lines of a 4x20
LCD, by using the custom characters shown in Figure 2.
It shows seven custom characters on line 2 of the LCD,
but the eighth custom character is a blank so it doesn’t
appear. The main project software loop (discussed later)
will create the hexadecimal number system and display
them in sequence, starting with the numbers 0– 9 and
then A–F, all in a large-character format that spans
all four lines. The number “1” is displayed in Figure 3
to illustrate what I’m trying to describe. Using large
numbers like this makes it very easy to read from across
If you remember the 2x16 LCD project that I did
in a previous column, then you will find the 4x20 LCD
has all the same connections. A great advantage to
using LCD modules is their common connection system,
which makes it easy to change from 2x16 to 4x20.
Figure 4 shows the connections to the Ultimate OEM
BasicATOM module. You can easily connect the LCD to a
PIC16F876A directly, by following the connection names
in the schematic.
This software listing is kind of long, but most of the
code deals with setting up the LCD to display the large
custom characters. (The complete software listing is
available on the Nuts & Volts website at www.
nutsvolts.com.) In the code, you will notice the “|” pipe
character at the end of several lines. This is for line
continuation. This is a special character that the BasicATOM
compiler recognizes as a continuation message. When the
compiler sees that character, it knows the command line
was too long for the editor window and continues on the
next line. Setting up the characters takes a lot of space, so
the line-continuation function is used often.
HOW IT WORKS
First, we establish a few variables and constants. The
variables are just temporary storage locations labeled X and
Char. The constants define the LCD “E” pin and “RS” pin.
■ FIGURE 4. Connections to the Ultimate
OEM BasicATOM module.
■ FIGURE 3. An example of a large character.
x var byte
char var byte
epin con 3
rspin con 0
‘Establish nickname for LCD enable pin
‘Establish nickname for LCD Register
The program initializes the LCD by first waiting a half
second for it to warm up, and then it issues the LCDWRITE
command to set it up as a two-line LCD. A 4x20 LCD is
really a two-line by 40 character LCD, with line 1 broken up
between lines 1 and 3, and line 2 broken up between lines
2 and 4, to form a 4x20 LCD.
‘ *** Initialize LCD ***
September 2007 15