Programming LCD GRAPHICS
in BASIC
via Printer Port

INTRODUCTION

This is the second part in the programming LCD series. Part I introduces a simple way of programming LCDs to display text messages via a PC printer port. Now we will show you it is as easy to produce LCD graphics at almost no extra cost except that of the LCD unit. The control concepts and programming procedures are similar in both types of LCDs. If you have gone through the exercise in Part I before, you will be an expert in programming graphical LCD modules in no time at all. Before you know it, you could be producing eye-catching LCD displays or even designing your own game gadgets just like those you have played when you were young.





Project Module

In addition to a +5 Voltage power supply to the LCD unit, the Vo of the LCD module requires a negative reference voltage between minus 5 to 6.5 volts. Therefore an extra negative Voltage Regulator is used to maintain the required differential voltage. Two 9-V batteries are needed to provide a dual power supply. Resistors between the printer port and the LCD are used to limit draining currents from the computer. Bits C0,C1 and C3 are countered inverted via transistors Q1,Q2 and Q3 to maintain positive logic and hence, be more straightforward for programming. A single bit is tapped to the printer input to read the busy bit from D7 of the LCD. Leds in the circuit indicating ports status are extremely useful in case of program debugging and circuit troubleshooting. Owing to the simplicity of the circuit, it is highly recommended for anyone to experiment the circuit on a breadboard.




Project Program

The program starts with declarations of LCD settings. It turns display on and defines starting coordinates on screen. The program then reads the graphics in ASCII codes and dumps them onto the display RAM. Another scene then is loaded and written on top of the existing scene to produce an animated effect. The program works on both XT and Pentium 120MHz machines. For higher end computers, time delay routines maybe necessary to accommodate LCD hardwares operating speed.

PROGRAM LISTING
20 REM Using Printer Port Control Program Name:horseart.BAS
30 REM HORSE ROUTINE 8x16 (8x8 DOT) blocks LCD 12864
110 DEFINT A-Z
120 DIM dataset(44, 8)
140 REM 44 screen patterns in ASCII codes
150 DATA &H00,&H00,&H00,&H00,&H00,&H80,&HC0,&HF0
170 DATA &HF8,&HF8,&HF8,&HFC,&HFC,&HFC,&HFC,&HF8
190 DATA &HFC,&HFE,&H7E,&H7E,&H7E,&H18,&H80,&H80
210 DATA &H80,&H80,&H80,&H80,&HC0,&HC0,&HE0,&HE0
230 DATA &HE0,&HC0,&H80,&H00,&H00,&H00,&H00,&H00
250 DATA &H00,&H00,&H00,&H00,&H00,&H80,&H80,&H00
270 DATA &H00,&H00,&H00,&H00,&H00,&H00,&H00,&H80
290 DATA &H80,&H80,&HC0,&HC0,&HC0,&HE0,&HE0,&HC0
310 DATA &HC0,&HC0,&HC0,&HC0,&HE0,&HE0,&HE0,&HF0
330 DATA &HF0,&HF0,&HF0,&HE0,&HE0,&HC0,&HC0,&H80
350 DATA &H00,&H80,&H8C,&H3F,&H3F,&H7F,&H7F,&HFF
370 DATA &HFF,&HFF,&HFF,&H2F,&H0F,&H8F,&HCF,&HEF
390 DATA &HF7,&HFF,&HFE,&HFE,&HFE,&HFD,&HFE,&HFE
410 DATA &HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&H3F,&H7F
430 DATA &H7F,&H7F,&H7F,&H7F,&HFE,&HFC,&HF8,&HE0
450 DATA &HC0,&H00,&H00,&H00,&H00,&H00,&H00,&H00
470 DATA &H00,&H00,&H00,&H00,&H00,&H01,&H0B,&H0B
490 DATA &H0F,&H2F,&H3F,&H3F,&H3F,&H5F,&H7F,&H7F
510 DATA &HBF,&HDF,&H7F,&H7F,&H3F,&H1F,&H0F,&H07
530 DATA &H03,&H3F,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF
550 DATA &HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF
570 DATA &HFF,&HFF,&HFE,&HFF,&HFF,&HFF,&HFE,&HFE
590 DATA &HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFE,&HFF
610 DATA &HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF
630 DATA &HFF,&HFF,&HFF,&H3F,&H0F,&H01,&H00,&H00
650 DATA &H00,&H00,&H00,&H00,&H00,&H00,&H01,&H01
670 DATA &H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00
690 DATA &H00,&H00,&H04,&H00,&H00,&H00,&H00,&H00
710 DATA &H00,&H00,&H00,&H00,&H01,&H03,&H67,&H6F
730 DATA &HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF
750 DATA &HDF,&H0F,&H07,&H0F,&H0F,&H1F,&H1F,&H1F
770 DATA &H3F,&H3F,&H3F,&H3F,&H3F,&H3F,&H3F,&H7F
790 DATA &HFF,&HFF,&HFF,&HFF,&H7F,&H7F,&HFF,&HFF
810 DATA &HFF,&HF3,&HE0,&HE0,&HC0,&H80,&H80,&H00
830 DATA &H00,&H01,&H01,&H03,&H07,&H07,&H0F,&H0F
850 DATA &H1F,&H3F,&H7E,&HFC,&HFC,&HF8,&H62,&HC6
870 DATA &H8C,&H0C,&H0C,&H18,&H18,&H18,&H30,&H70
890 DATA &H73,&H77,&H7F,&H3F,&H00,&H00,&H00,&H80
910 DATA &HC0,&HE1,&H31,&H39,&H1D,&H0F,&H0F,&H03
930 DATA &H00,&H00,&H00,&H00,&H00,&H03,&H1F,&H3E
950 DATA &H7B,&HC7,&HCE,&H98,&H30,&H70,&H60,&H40
970 DATA &H00,&H00,&H00,&H00,&H00,&H03,&H03,&H01
990 DATA &H00,&H00,&H01,&H01,&H00,&H00,&H00,&H00
1010 DATA &HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF
1015 slow = 80
1020 FOR i = 1 TO 44
1030 FOR j = 1 TO 8
1040 READ dataset(i, j)
1050 NEXT j
1060 NEXT i
1070 SET$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .abcdefghijklmnp~"
1080 message$ = " "
1082 message$ = message$ + " ABCDE "
1084 message$ = message$ + " FGHIJKLMNOP "
1086 message$ = message$ + " QRSTUVWXYZ "
1088 message$ = message$ + " abcdef "
1090 message$ = message$ + " ghijk "
1092 message$ = message$ + " lmn "
1094 message$ = message$ + " p "
1130 REM CLEAR SCREEN
1140 Y = 0: K = 0: n = 0
1150 FOR j = 0 TO 1023
1160 IF n <> 0 + K GOTO 1220
1170 x = 0 + Y
1180 p = 8
1190 q = 0
1200 GOSUB 1750
1210 GOTO 1270
1220 IF n <> 64 + K GOTO 1270
1230 p = 16
1240 GOSUB 1750
1250 K = K + 128
1260 Y = Y + 1
1270 a = 0
1280 GOSUB 1870
1330 n = n + 1
1340 NEXT j
1350 REM 8x8 dot graphic matrix GENERATION
1360 Y = 0: K = 0: n = 0
1370 FOR j = 1 TO 128
1380 char$ = MID$(message$, j, 1)
1390 FOR jj = 1 TO 44
1400 IF char$ = MID$(SET$, jj, 1) GOTO 1440
1410 NEXT jj
1440 FOR i = 0 TO 7
1460 IF n <> 0 + K GOTO 1520
1470 x = 0 + Y
1480 p = 16
1490 q = 0
1500 GOSUB 1750
1510 GOTO 1580
1520 IF n <> 72 + K GOTO 1580
1530 p = 8
1540 q = 0
1550 GOSUB 1750
1560 K = K + 144
1570 Y = Y + 1
1580 a = dataset(jj, i + 1)
1590 GOSUB 1870
1600 IF jj = 27 GOTO 1640
1640 n = n + 1
1650 NEXT i
1680 n = n + 1
1700 NEXT j
1730 END
1740 STOP
1750 REM SUBROUTINE Instruction
1760 B = 0
1770 a = &H3F
1780 GOSUB 1870
1790 a = &HC0
1800 GOSUB 1870
1810 a = &HB8 + x
1820 GOSUB 1870
1830 a = &H40 + q
1840 GOSUB 1870
1850 B = 4
1860 RETURN
1870 REM SUBROUTINE Print
1890 OUT &H37A, 2 + p
1900 OUT &H37A, 3 + p
1910 C = INP(&H379)
1920 OUT &H37A, 2 + p
1930 C = C AND &H8
1940 IF C = 0 GOTO 1970
1950 PRINT "busy"
1952 FOR kk = 1 TO slow
1954 kkk = kkk + kkk
1956 NEXT kk
1960 GOTO 1890
1970 OUT &H378, a
1990 OUT &H37A, B + 1 + p
2000 OUT &H37A, B + p
2010 RETURN




Conclusion

This simple project introduces basic steps in programming a graphical LCD unit. The printer port interface greatly facilitate the process. The outlined procedure is simple enough for anyone to follow yet it could be a stepping stone to producing eye-catching graphics. This hot technology not only entertains the enquiring minds of hobbyists but also opens the door to developing potential career in games, visual aids and electronic advertisement.

1