RSS Feed Email Facebook Twitter Stumbleupon Google Bookmark

LCD Project

Controlling an LCD with a PC Parallel Port

While waiting for the hardware design to be completed on a project using a standard 4x20 LCD, I decided to get a jump start on the software by prototyping the LCD portion of the project on a PC, connecting the LCD to the printer port. It worked out so well that I decided to share what I'd done.

The circuit is pretty simple. The data lines on the LCD match up well with the data lines of the parallel port, and extra parallel port I/O lines can be used to simulate the RS, R/W, and E signals on the LCD. The LCD module is pretty low-lower (with the exception of the backlight), so I found that it can be powered from most parallel ports. It worked fine with all the desktop PC's I tried it with, but a laptop I tried (a Toshiba something-or-other) just didn't have enough oomph to power the LCD ...

Anyway, here's the circuit:

Printer-to-LCD Interface Circuit

The 10K pot controls the contrast of the LCD, though, in practice, I've found that it usually ends up at the ground rail, so you might be able to get by without the pot, and just tie VLC to ground.

The diode from pin 17 of the printer port to pin 2 of the LCD simply blocks voltage from flowing back into the printer port (in case you hook up an external power supply). If you use an external supply, it's intended to connect to the place on the schematic labeled "+5V". This external supply can also be used to power the LCD's LED backlight (through a current-limiting resistor -- 100 ohms is probably too high, but it will turn the backlight on at least dimly).

I built this circuit up on a little Radio Shack protoboard, using a DB25 for the printer port connector, and a 16-pin terminal strip for the LCD connector, with the interconnects on the back. Not pretty, but it works fine ...


Source Code

I wrote the code in C, and compiled it with Borland C/C++ v3.1, though you could use QuickBASIC or anything else that gives you access to the parallel port. (Visual Basic for Windows doesn't give you low-level access to the printer port, so you'd have to use a DLL such as IOVBX or VBASM if you want to use VB. See the Parallel Port page for links.)

Here's the code (LCD_4X20.ZIP), which includes low-level control, higher-level routines, and a demonstration program, which is also included in executable form, so you can just plug in your LCD and test it right away.

LCD_4X20.C contains the routines to control the LCD. Most of them are fairly generic, except for the ones at the end of the file, which are the low-level routines that handle the parallel port interface. If you want to use this code on a microcontroller such as the HC11, this one small section is all you'd need to change.

LCD_4X20.H is the header file for LCD_4X20.C, and contains all the function prototypes for the public routines. Just #include this header file in whatever program you're writing.

LCD.C is a simple little program that demonstrates how to use the routines in LCD_4X20.C. It displays a menu on the PC screen, and controls the LCD to demonstrate:

  • Initializing the LCD.
  • Clearing the LCD.
  • Positioning the cursor.
  • Displaying a string.
  • Displaying a screen.
  • "Wiping" a screen clear, then "wiping" another on in its place.
  • Displaying multiple pages of text.
  • Using special user-defined characters.
  • Implementing a menu.
  • Flashing text.
  • Creating a "marquee" -- a line of text that scrolls across the screen.
  • Displaying a bar graph.
  • Centering text on a line.

This code really does quite a lot. If you've never used an LCD module before, I think you'll be surprised at some of the effects that can be achieved.


LCD Links


blog comments powered by Disqus