This is only a preview of the March 1998 issue of Silicon Chip. You can view 43 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 "Sustain Unit For Electric Guitars":
Items relevant to "Multi-Purpose Fast Battery Charger; Pt.2":
Items relevant to "Command Control For Model Railways; Pt.3":
Items relevant to "PC-Controlled Liquid Crystal Display Board":
Articles in this series:
Articles in this series:
|
A liquid crystal
display driven from
a PC printer port
Last month we published a demo board which let
you manually feed text into a one-line alphanumeric
display by manipulating switches. This month we
take the same one-line display and hook it to the
parallel port of a PC to produce moving messages.
By RICK WALTERS
66 Silicon Chip
Fig.1: horribly complicated, innit? The display
requires 8 bits of data, a register select line, a
strobe line and a 5V supply.
Fig.2: the component overlay for the PC board.
Parts List
1 PC board, code 04104981, 81 x
58mm
1 Liquid Crystal Display with HD44780
controller
1 25-way “D” male PC mount connector
1 20kΩ PC trimpot
1 100µF 25VW PC electrolytic capacitor
1 0.1µF MKT polyester capacitor
1 15-pin “D” male connector (for +5V
from games port)
Fig.3: actual size artwork for the PC board.
D
ID YOU DECIDE to have a go at
the demo board last month or
did you feel that all those
switches were just not worth the has
sle? Well, some of us at SILICON CHIP
are quite lazy too and they (no names,
no pack drill) thought that this sort of
drudgery is the sort of task that com
puters are ideal for. So the boss told
me, “Some readers won’t be bothered
with all that. You’d better do a version
which can be driven from the parallel
port of a PC”. Naturally I saluted and
said “It will be done”. And here it is.
So if you want all the hard work
to be done for you by a computer so
that you can display moving messages
or create, save and display your own
symbols, get stuck into this extremely
simple project.
It uses the same one-line 16-char
acter Liquid Crystal Display (LCD) as
previously with an HD44780 control
ler. This is mounted on a small PC
board with a 25-way male D connector
to mate with a standard 25-way cable
from the parallel port. A trimpot and
a couple of capacitors complete the
assembly. The trimpot is used to ad
just the optimum contrast for different
LCD operating param
eters. The 5V
for the display can be provided by a
power supply or taken from the games
port of the computer. You could even
use the 9V battery and regulator setup
as in the previous article.
To get the display working requires
eight bits of data, a register select line,
a strobe line and a 5V supply. The
circuit arrangement is shown Fig.1.
The 8-bit data we use for the display
is the same eight bits that a printer
uses and we also use two of the printer
control lines for the other functions
we need; ie, register select (RS) and
strobe.
When the register select line is
low (ground) it allows the computer
to send internal commands to the
LCD and when it is high (5V) we can
write to the LCD screen. The printer
port line we use to control the RS
line is port C bit 3. This is the only
line from this port that does not have
inverted logic.
When logic highs are output from
the computer to port C, only bit 3 will
be high; the other three bits (1, 2 and
4) will be low (inverted). From this
you can see that when we require the
March 1998 67
Listing 1: LCD Driver Program
10 REM Driver program for single line LC Display
11 ‘driven from the parallel port of a PC
12 ‘R.W. 23/11/97 V1.0
20 GOSUB 1000 ‘Initialise software routines
30 GOSUB 2000 ‘Initialise display
40 GOSUB 3000 ‘Write data to display
50 GOSUB 6000 ‘Scroll message back & forth
60 GOSUB 7000 ‘Scroll message to left & wrap
70 GOSUB 8000 ‘Create your own character
999 END’ CLS: SYSTEM
1000 ‘***********************
1010 ‘Initialisation routine.
1020 ‘***********************
1030 KEY OFF: CLS: DEFINT A,B,S: DEFSTR D,K
1035 ‘A,B,S integers, D,K are strings, rest single precision
1040 DEF FNCEOL$ = STRING$(79 - POS(Q),” “)
1050 DEF FNCENTRE$(M$) = SPACE$((78-LEN(M$))/2) + M$
1400 PORTA = &H378 ‘This is LPT1, use &H278 for LPT2
1410 PORTC = PORTA + 2 ‘Define Port C. Port B is not used
1420 COMMAND = 0: CHR = 4: STH = 0: STL = 1 ‘Define function & STrobe
1999 RETURN
2000 ‘*******************
2010 ‘Initialise display.
2020 ‘*******************
2030 FUNCT = COMMAND: OUT PORTA,0 ‘Define RS & set LCD inputs low
2040 GOSUB 4040 ‘clock RS line low
2050 OUT PORTA,48: GOSUB 4000
2060 T = TIMER: WHILE T + .03 > TIMER: WEND ‘wait 30ms
2070 GOSUB 4000
2080 T = TIMER: WHILE T + .01 > TIMER: WEND ‘wait 10ms
2090 GOSUB 4000
2100 OUT PORTA,60: GOSUB 4000 ’16 character display
2110 OUT PORTA,14: GOSUB 4000 ‘display & cursor ON, UNDERLINE cursor
2120 OUT PORTA,1: GOSUB 4000 ‘clear home
2130 T = TIMER: WHILE T + .01 > TIMER: WEND ‘clear home can take 5ms
2999 RETURN
3000 ‘*******************
3010 ‘Write data to Port.
3020 ‘*******************
3030 FUNCT = CHR ‘Set register select line high
3040 GOSUB 4040 ‘Clock RS line high
3050 DAT = “Silicon Chip is a great magazine.”
3060 FOR A = 1 TO LEN(DAT): TOWRITE = ASC(MID$(DAT,A,1))
3070 OUT PORTA,TOWRITE
3080 GOSUB 4000 ‘Clock full message into LCD from left hand edge
3090 NEXT
3100 GOSUB 5000 ‘Locate cursor at 64 decimal
3110 FOR A = 9 TO LEN(DAT): TOWRITE = ASC(MID$(DAT,A,1)) ‘Write nessage
3120 OUT PORTA,TOWRITE ‘starting at position 9 i.e. “C” for correct scroll
3130 GOSUB 4000 ‘Clock data into LCD
3140 NEXT
3999 RETURN
4000 ‘**********
4010 ‘Clock LCD.
4020 ‘**********
4030 OUT PORTC,FUNCT OR STL ‘Set R/S line & take strobe low
4040 OUT PORTC,FUNCT OR STH ‘Set R/S line, take strobe high.
4999 RETURN
5000 ‘***************************
5010 ‘Shift cursor to Position 9.
5020 ‘***************************
5030 FUNCT = COMMAND: OUT PORTC,FUNCT OR STH ‘Set command mode
5040 OUT PORTA,64: GOSUB 4000 ‘Set CG to 9
. . . continued next page
68 Silicon Chip
strobe to be high we actually have to
output a low and vice versa.
If you look at Listing 1, on line 1420
you will see that STH (strobe high)
is defined as 0 (low) and STL (strobe
low) is defined as 1 (high). This allows
us to forget about the logic inversion
and just select the strobe logic level
we want. The strobe line is normally
held high and is taken low to transfer
information from the data lines to the
display.
The LCD commands for the
HD44780 controller are listed in Ta
ble 1 and the character set is listed in
Table 2, as published in last month’s
issue.
After initialising the LCD, the
software (Listing 1), firstly writes a
string of text, which is longer than the
16 character window, to the display.
This message then scrolls backwards
and forwards until a key is pressed,
whereupon it will scroll in a contin
uous loop, disappearing on the left
side of the window, then scrolling in
from the right.
Another keypress will clear the
display screen then write a custom
symbol to the first eight positions.
The Listing should make it clear how
you code the symbol you want. With
a little ingenuity you can create and
place two or three symbols side by
side to make a shape.
With each of these functions writ
ten as a complete subrou
tine, you
should have no trouble customising
the Listing to suit your particular
needs.
Board assembly & testing
We will not insult you by telling
you how to assemble the PC board.
It should be quite apparent from the
overlay diagram of Fig.2 and should
not take more than a few minutes. Be
sure to double check the orientation
of the electrolytic capacitor for correct
polarity.
The display will only draw 4-5mA
from its power supply so it does not
impose any significant load. If you
intend to power the display from the
PC, connect a wire from the battery
positive terminal to pin 1 on the 15way “D” connector, then plug the PC
board into the end of the cable, the
cable into the printer port and the 15
way connector into the games port.
Turn the computer on, load GW-Ba
sic or Q-Basic and type in listing 1.
If this gives you the horrors, you can
get the complete listing from SILICON
CHIP on a floppy disc at $7 plus $3
postage and packing.
Make sure that you enter the printer
port you intend to use on line 1400.
When you run the program the results
should be as previously described.
To change the message just enter a
different string for DAT in line 3050.
Don’t forget to enclose it in quota
tion marks and remember it is case
sensitive.
Understanding the display
The single line display we have
used has a few quirks. Instead of the
addresses of the 16 visible characters
being continuous from 0-15, the first
eight characters reside in addresses
0-7, while the second visible group
of eight reside at addresses 64-71.
All addresses are given in decimal
as this is how both versions of Basic
communicate with the printer port.
Note that we are talking about vis
ible addresses but there are actually
80 addresses available, 0-40 and 64104. This is the reason for subroutine
5000. After writing the full string of
33 characters starting from address 0
(lines 3060-3090), only the first eight
will display. We then call subroutine
5000 to move the cursor to display
position 9 or location 64. We then
write from the 9th character to the
33rd again but only the next eight
(“Chip is”) will show.
By changing or adding lines be
tween 40 and 999, changing the mes
sage in subroutine 3000 and creating
your own characters, you should soon
become an expert with Liquid Crystal
Displays.
Acknowledgement
Our thanks to Branco Justic of Oat
ley Electronics for assistance in the
SC
development of this project.
How To Get The Software
The software shown in Listing 1
is available on floppy disc for $7
plus $3 postage and packing.
Send your remittance or credit
card authorisation (Bankcard,
Visa or Mastercard) to Silicon
Chip Publications, PO Box 139,
Collaroy Beach, NSW 2097.
Don’t forget to nominate whether
you want a 3.5-inch or 5.25-inch
floppy disc.
Listing 1: LCD Driver Program – continued
5050 OUT PORTA,192: GOSUB 4000 ‘Set DD to 9
5060 FUNCT = CHR: OUT PORTC,FUNCT OR STH ‘Restore character function
5999 RETURN
6000 ‘************************
6010 ‘Scroll message to & fro.
6020 ‘************************
6030 FUNCT = COMMAND: OUT PORTC,FUNCT OR STH ‘Set command mode
6040 LOCATE 25,1: PRINT FNCENTRE$(“Press a key to end this demonstration.”);
6050 OUT PORTA,24 ‘Shift data left
6060 FOR A = 1 TO LEN(DAT) - 1: GOSUB 4000
6070 K = INKEY$: IF K > “” THEN 6990
6080 T = TIMER: WHILE T + .5 > TIMER: WEND ‘Wait 0.5 seconds
6090 NEXT
6100 OUT PORTA,28 ‘Shift data right
6110 FOR A = 1 TO LEN(DAT) - 1: GOSUB 4000
6120 K = INKEY$: IF K > “” THEN 6990
6130 T = TIMER: WHILE T + .5 > TIMER: WEND
6140 NEXT
6150 GOTO 6050
6990 LOCATE 25,1: PRINT FNCEOL$;: LOCATE 1,1
6999 RETURN
7000 ‘***********************************
7010 ‘Scroll message to left continuously.
7020 ‘************************************
7030 FUNCT = COMMAND: OUT PORTC,FUNCT OR STH ‘Set command mode
7040 LOCATE 25,1: PRINT FNCENTRE$(“Press a key to end this demonstration.”);
7050 OUT PORTA,24 ‘Shift data left
7060 FOR A = 1 TO LEN(DAT) * 32: GOSUB 4000
7070 K = INKEY$: IF K > “” THEN 7990
7080 T = TIMER: WHILE T + .5 > TIMER: WEND
7090 NEXT
7990 LOCATE 25,1: PRINT FNCEOL$;: LOCATE 1,1
7999 RETURN
8000 ‘**************************
8010 ‘Create your own character.
8020 ‘**************************
8030 ‘000 01110 decimal 14
The 1’s represent pixels that will
8040 ‘000 11011 decimal 27
be written (black)
8050 ‘000 00000 decimal 0
The 0’s will appear as background
8060 ‘000 00100 decimal 4
so the character will have the shape
8070 ‘000 10101 decimal 21
of the 1’s i.e. a crude smiley face
8080 ‘000 01010 decimal 10
Only the right 5 rows are significant
8090 ‘000 00100 decimal 4
The left 3 rows are ignored
8100 ‘000 00000 decimal 0
8110 FUNCT = COMMAND: OUT PORTC,FUNCT OR STH ‘set command mode
8120 OUT PORTA,1: GOSUB 4000 ‘clear home
8130 T = TIMER: WHILE T + .01 > TIMER: WEND ‘clear home can take 5ms
8140 OUT PORTA,64: GOSUB 4000 ‘Set RAM address 01000000
8150 FUNCT = CHR: GOSUB 4040 ‘Set character mode
8160 OUT PORTA,14: GOSUB 4000 ‘Start sending your character
8170 OUT PORTA,27: GOSUB 4000
8180 OUT PORTA,0: GOSUB 4000
8190 OUT PORTA,4: GOSUB 4000
8200 OUT PORTA,21: GOSUB 4000
8210 OUT PORTA,10: GOSUB 4000
8220 OUT PORTA,4: GOSUB 4000
8230 OUT PORTA,0: GOSUB 4000 ‘After the 8th bit
8240 FUNCT = COMMAND: GOSUB 4040 ‘change the RS line
8250 OUT PORTA,1: GOSUB 4000 ‘and clear/home the display
8260 T = TIMER: WHILE T + .01 > TIMER: WEND ‘Clear home can take 5ms
8270 FUNCT = CHR: GOSUB 4040 ‘Revert to character mode
8280 OUT PORTA,0: GOSUB 4000 ‘and load our character stored at location 0
8290 FOR B = 1 TO 7:GOSUB 4000: NEXT ‘Then write it to the next 7 locations
8999 RETURN
March 1998 69
|