This is only a preview of the February 1998 issue of Silicon Chip. You can view 29 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Multi-Purpose Fast Battery Charger; Pt.1":
Items relevant to "Command Control For Model Railways; Pt.2":
Items relevant to "Demonstration Board For Liquid Crystal Displays":
Items relevant to "Build Your Own 4-Channel Lightshow; Pt.2":
Articles in this series:
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Demo board for
liquid crystal displays
Ever wondered how an alphanumeric liquid
crystal display translates digital data into
a readable message? Then wonder no more
and build this neat little demo project which
uses a one-line alphanumeric LCD.
By RICK WALTERS
These days almost every electronic
doodad seems to have an LCD in it.
From those horrible little Tamagochi
hand games to the ubiquitous bat
phone (What? You still call yours a
mobile?) to photocopiers and faxes,
they’re everywhere. However did we
function without LCDs? Maybe life
was simpler then . . .
Anyway, how do these LCDs work?
Most LCDs are not just the bare liquid
crystal display with a whole bunch of
connections made via an elastomeric
connector to an external circuit. In
stead, most one and two-line alpha60 Silicon Chip
numeric displays have a processor
encapsulated in a blob of black plastic
on the back. Alternatively, the processor might be a surface mount device
on the back of the display.
Either way, the principle of operation is much the same. Parallel
8-bit data is fed in on a bus and this
is converted by the processor to be
displayed.
Before we go any further, we had
better define what we mean by “alphanumeric”. This merely means that
the display can handle alphabetic
and numeric characters; ie, numbers
and letters. More to the point, most
alphanumeric displays can handle
most of the 256 characters possible
in the ASCII character set.
Typically they can display all upper case and most lower case letters,
numbers, punctuation marks, mathematics symbols such as plus, minus,
division, percentage, greater than, less
than and so on, some Greek symbols,
the dollar sign, asterisk, hash and
perhaps some Kanji symbols from the
Japanese language.
For this demo project we have used
an LCD employing the very common
Hitachi HD44780 LCD controller chip.
It converts the 8-bit data into characters employing a 8 x 5 dot matrix.
This same dot matrix, by the way, is
used in cheap dot matrix printers. Obviously then, the on-board processor
does a translation (decode) between
8-bit ASCII characters to an 8 x 5 dot
matrix display, as well as providing
the buffer to display a full line of
characters.
As you can see, the demo project
Fig.1: the circuit uses eight
switches to load binary data
into the LCD controller.
IC1 is used to debounce the
LOAD switch S10.
consists of the chosen LCD panel together with a row of 10 switches on
it. Eight of the switches are for setting
the 8-bit data, while the other two are
for actually loading the data into the
display. There are some other bits on
the board as well but we’ll come to
those later.
Now you might think at this stage
that this project is not all that practical, particularly if you are thinking
of loading in long messages by hand!
You’d have to be working all those
switches like a veritable whirlwind
if the message was to be displayed in
a reasonable time. No, that is not the
purpose of the project. It is merely
a learning tool which will give you
some knowledge of how ASCII characters are displayed onto an 8 x 5 matrix.
It will also be useful if you are
beginning to write software to drive
a display with a microprocessor or
the parallel port of a computer, as it
allows you to check that the function
you are coding does actually work as
intended.
As you can see from the circuit of
Fig.1, apart from the switches and
the LCD panel itself, there are a few
resistors, three capacitors, a voltage
regulator, a 7555 CMOS timer and
a battery to get the display working.
Keen-eyed readers will have also
noticed an 8-way DIP switch on the
board but that is there as a cheap
alternative to the individual toggle
switches. The DIP switches are more
difficult to use if you want to load
in a lot of data but they could be a
practical alternative if you envisage
using this project just to display one
message. As I am writing this article
I am absolutely devoid of ideas on
what such a message might be, but I
am equally sure there will be heap of
uses out there.
Mind you, there are two drawbacks
to using the 8-way DIP switch to replace the logic level input switches
S1-S8. For a start, the DIP switches are
much more difficult to set. Second,
the data must be entered backwards as
the most significant bit is on righthand
side of the switch, whereas binary
numbers are conventionally written from left to right with the most
significant bit on the left. Makes it a
bit tricky, eh?
On the other hand, some readers
seem to thrive on a challenge.
For those readers who want the
easier life, the convention
al toggle
This photograph shows the old display at top with the “black blobs” and the
new display with the HD44780.
February 1998 61
Fig.2 (left): the component
overlay shows all 11 toggle
switches and the alternative
8-way DIP switch.
Fig.3 (below): actual size
artwork for the PC board.
switches are laid out to accept
conventional data.
How it works
There are two types of information which the controller
chip can accept: commands and
data. A command is an instruction which tells the controller
to do something internally, such
as set an 8 or 16-character display, home the cursor, clear the
display etc. Data consists of the
character or characters we wish
to show in the display window.
These instructions are differentiated by the logic level on
pin 4 (register select). This pin
is taken low (ground) to input
a command and high (5V) to
input data. The value of the
input is set, in 8-bit binary, by
the switches D0 to D7 (or the DIP
switch). Once the value is entered it
is transferred to the display by taking
pin 6 (enable) low.
So what is the reason for the 7555
timer IC? Why not connect the switch
directly to pin 6 of the display and
save on the cost?
If you did this you would be very
disappointed with the result. The
first character you entered would
probably fill the entire display due to
the switch’s contact bounce. When a
switch is actuated it never just closes.
As the contacts make, their momentum causes them to “bounce” apart,
then make, then bounce.
This can continue for 30ms or so.
When you turn on a light or a jug,
62 Silicon Chip
the bounce doesn’t matter but as the
display only takes 40µs to process the
instruction, it sees each bounce as a
new instruction and will write the
character over and over.
The capacitor fitted across the
switch is discharged on the first
“make” and cannot rapidly charge
through the 470kΩ resistor. This time
constant of 47ms ensures that the
logic level cannot go high again until
the switch contacts stop bouncing.
OK but why use the 7555? Couldn’t
the junction of the resistor and capacitor go directly to pin 6? The answer
is yes but then the transition time
of the waveform would be too slow
around the switching threshold of
the HD44780 and there is the possi-
bility of at least two characters being
written.
The IC output has very fast rise and
fall times which are more suited to the
display characteristics. Don’t forget,
the display was designed to be driven
from a microprocessor.
Pin 5, the read/write pin, is tied
permanently low as, with this simple
setup, we cannot read information
from the display.
VR1, the 10kΩ contrast control, is
necessary as its optimum setting varies depending on the display length,
duty cycle or character mode. We’ll
talk more about this aspect later.
Building the PC board
The first step is to check the PC
Table 1: HD44780 Instructions
good contact with its
respective gold-plated
contact. This approach
allows you to easily
remove the display and
use it in other projects.
You will need to check
continuity from each
pin to the display pad
to ensure that they are
all making contact.
Check that the polarity of the electrolytic
capacitor is correct and
that the DIP switch is
fitted facing the right
direction. Also double
check that the battery
leads are soldered into
the correct pads before you connect the
battery.
Lastly, fit a self-adhesive foot to each corner of the PC board to
prevent it from sliding
around while you are
setting the switches
and also to protect
any surface it may be
placed on.
Testing the display
pattern against the artwork of Fig.3,
ensuring that the tracks between the
switch pads don’t short and that none
of the tracks are broken. Any necessary repairs should be done now.
To keep the cost low we have
screened the switch information on
the top of the PC board as there seems
little point in putting it all in a case.
The first step is to fit and solder the
four links as shown on the component overlay diagram of Fig.2.
Next, fit and solder the resistors,
trimpot, IC, capacitors, pin header,
regulator, battery clip, then lastly
the switches, making sure that the
spring- loaded toggle is fitted at the
righthand end of the board and the
switch action is towards the 7555
timer. The centre pin of the regulator
will have to be bent away from the
flat to fit the PC board.
We have specified a 14-pin strip to
connect the display pins to the PC
board. There is no need to solder the
pins to the display board – just bend
them slightly so that each makes
Turn the contrast
control VR1 fully anticlockwise, plug in
the battery and turn
the power on. Eight
dark rectangles should
show at the left half
of the display. When
power is applied the
controller initialises an
eight character display
and these are what you
can see. The contrast
control should now be
turned clockwise until
these rectangles just
disappear.
Before we can do any further testing
we need to give just a short burst on
binary numbers. We are all used to
dealing with decimal (power of 10)
numbers which have 10 digits (0-9).
As the name suggests, binary (power
of two) numbers have just two digits
(0 & 1). We use the switches S1-S8 to
select either of these values, a zero
being a low logic level and a one being
a high logic level.
There are eight input switches, so
to define the position of each switch
February 1998 63
Table 2: Character Codes vs. Character Patterns
(hence each input instruction) we
issue a string of eight binary digits
(or bits), always starting with bit 8.
For example, the command for ‘turn
display and cursor on, with cursor
position underlined’ is 00001110.
This means S1 and S5-S8 would be
turned off (down) while S2, S3 and
S4 would be turned on (up). This was
done to match the DIP switch which
is up for on.
All the commands are shown in
Table 1. As it is quite difficult to speak
and think in binary, most people
prefer to use decimal, or if you are a
computer boffin, then you must talk
Hexadecimal (power of 16) which
uses the digits 0-9, then A-F for the
next six. The table also shows these
values.
Now back to the testing. If you set
the switches to 00001110, the func64 Silicon Chip
tion switch to command (CMD) and
actuate the LOAD switch, an underline will appear at the first position.
So the code actually worked. If you
are using the DIP switch 2, 3 and 4
would be ON, the rest OFF.
Table 3:
User Designed Character
Binary
Decimal
H ex
0000 1110
14
E
0000 0000
0
0
0001 1011
27
1B
0000 0100
4
4
0000 0100
4
4
0001 0001
17
11
0000 1010
10
A
0000 0100
4
4
OK, now let’s do something a little
more useful and enter some data. The
fist step is to switch S9 from command
to data. Keeping it simple, we will
enter the characters A-P. The 8 bits
for each letter of the alphabet, as well
as all the characters the display is
capable of, are shown in Table 2. Set
the capital A, 01000001, and load it
with S10. Hopefully an A will display
and the cursor will step to the next
position. Continue to enter the letters.
What happened to I? A 16-character
display with only eight characters is
not much use.
This is the difference between early
displays similar to the one used in
the SILICON CHIP article in May 1993,
which had a continuous address
space for the sixteen characters. The
old style displays (see photo) had two
black blobs on the PC board, which
have been replaced by the HD447870.
Unfortunately, but for compatibility
reasons, it has the addresses of the
first eight characters from 0 to 8 but
the second eight characters from 64
to 71 decimal (40H to 47H).
Now let’s try again. We must set
the display for 16 characters. Set the
switches for 00111000, the function
switch to command and load the
instruction. The contrast control
will need to be reset slightly for optimum viewing as the duty cycle has
changed. Load 00000001 to home
the cursor and clear the screen, then
change to data and begin loading the
alphabet again.
This time after you load H the cursor will disappear. Using COMMAND
and 01000000 will restore the cursor,
but when you try to enter characters
the cursor steps but writes blanks. Use
01000000 and command to bring it
back to position 9 then load command
11000000. Now when you continue
entering the alphabet all is well.
Look up these last two commands
in Table 1 to see what they actually
did.
Moving the text
Up until now we have stepped the
cursor forward each time we entered
a character but it is also possible to
keep the cursor stationary and move
the text either to the left or to the right.
Again from Table 1, the command for
“shift left” is 000011000 and “shift
right” is 00011100.
As we saw previously, if you enter
more than eight characters starting
from position 1, they don’t appear
on the display. They are still being
stored in RAM though and can be
moved backwards and forwards in the
display window by using either of the
above instructions in command mode
and loading it. Try it for yourself.
The only thing left to do now is
to create our own symbols. Up to
16 custom symbols can be stored in
CGRAM but they must be loaded each
time the display is powered up. This
is because they are stored in static
RAM and they are lost when power
is removed. If you were using a micro
it would be easy to load them at each
power up.
Symbol creation
If you look closely at the display,
with the contrast adjusted to see the
black rectangles, you will observe
that the characters are made up using
an 8 high by 5 wide dot matrix. Each
of these dots (pixels) is addressable
and this is why we can create our
own symbol.
To program a symbol the first step is
to draw it on the righthand side of an
8 by 8 grid (see Table 3). The lefthand
three digits are always zeros. The
Parts List
1 PC board, code 04102981,
127 x 77mm
1 one-line Liquid Crystal Display
with HD44780 controller
10 SPDT toggle switches or
2 SPDT toggle switches and
1 8-way DIP switch (see text)
1 SPST spring-loaded toggle
switch (S10)
1 78L05 5V regulator
1 9V battery
1 battery snap connector
1 14-way pin strip
4 2.5 x 15mm machine screws
12 2.5 mm nuts
4 12 x 12mm adhesive rubber
feet
Capacitors
1 100µF 16WV PC electrolytic
1 0.1µF MKT polyester
1 0.1µF monolithic ceramic
Resistors (0.25W, 1%)
1 470kΩ
8 15kΩ
1 20kΩ PC trimpot (VR1)
choice is limited but we shall draw
a crude smiley face. Clear and home
the display then set the address to
01000000 and load it. Change to character and load the eight binary numbers starting from the top (00001110).
After the eighth has been entered,
switch to command and clear the
display. Switch back to data and write
01000001 which should be a capital
A (just to check everything is still
working), then write 00000000 which
will display our face. The first saved
symbol is stored in location zero (even
though we wrote it at position 64, and
the next fifteen are saved in locations
1 to 15. This is shown in Table 2.
Well, that covers the capabilities
of this simple display. It can’t show
10 by 5 or true lower case characters,
but the knowledge you have gained
will apply to multi-line and 10 x 5
displays.
Computer control
Next month, we will use this same
LCD panel in a project which can be
driven from a PC’s parallel port. It
won’t be so much of a learning experience but it is a heck of a lot quicker
SC
to get a readable message.
February 1998 65
|