LCDs - Why You Need One
A liquid crystal display, better known as an LCD, is an excellent way for a microcontroller to present visible information. LCDs can display output from the µC such as time, date, and temperature; they can also be used to display the contents of memory, and aid in debugging programs.
LCDs are available in several sizes, and two of the most common configurations are 16 characters in each of two rows (16x2) and 20 characters in each of four rows (20x4). For general purpose use, a 20x4 can display more than twice as much information as a 16x2 and for very little more money. Therefore, a 20x4 will be the display of choice in future projects and technical articles on AAC by this author.
A variety of LCD colors are also available, and while red and orange have their place, more sedate colors like blue and green may be easier on the eyes over the long haul. A photo of the author's 20x4 display is shown below. Note all the information shown: day, time, date, current temperature, 24 hour high temperature, 24 hour low temperature, and the status of eight different alarms. The entire system was controlled by a PICAXE 20X2.
LCDs are more than just display panels. Most include sophisticated electronics that accept data and convert the data to letters, numbers, and symbols that appear on the display. The format and protocol for input to an LCD is not the same for all displays, and there is no universally accepted standard. However, one method that is commonly used was originated by Hitachi and is referred to as the HD44780 format. It is the format of choice by this author and is highly recommended.
HD44780 compatible displays commonly have 14 or 16 input connections (depending upon whether or not the display includes a back light) and accept data in parallel format. A pinout table for a typical HD44780 display is shown below.
|5||R/W||Read / Write|
|15||A||Anode of Backlight LED|
|16||K||Cathode of Backlight LED|
As you see, there are eight data leads and HD44780 displays can accept 8-bit data. In addition to the data leads, the enable (E) lead and register select (RS) lead are needed. Thus, 10 I/Os are occupied on the microcontroller for 8-bit parallel data. The HD44780 can also operate on 4-bit data, which is a help, but with the additon of the two control leads, 6 I/Os are still used. Given that a 20-pin µC can have no more than 18 I/Os, dedicating 10 or even 6 of them to a display seems excessive. Using an LCD with an even smaller microcontroller can be impossible, so what can be done?
Serial to Parallel LCD Adapter
In order to conserve microcontroller I/Os, data can be sent in serial format via a single pin, but an HD44780 display cannot receive serial data. One solution is to use a separate, dedicated microcontroller with specialized code to convert the serial data to parallel and feed it to the LCD. That is the approach that is selected for use here.
Once again, no standard exists for the serial to parallel conversion protocol, and several different methods are in common use. One of the best programs was written by Peter Anderson and was sold in pre-programmed pics to thousands of satisfied customers. Professor Anderson died in 2012, and true to his sense of fair play, he stipulated that his code be put into the public domain. Thus, if you have the ability to program a PIC microcontroller, you can download his code, load it into your PIC, and with the addition of a few components, build your own serial to parallel LCD adapter. Anderson even left a hand drawn schematic to get you started. For those who are unable to program PICs, pre-programmed chips are still available from two different suppliers: Modern Device and Wulfden.
Another convenient option is to simply buy a kit that includes the programmed PIC, a custom printed circuit board, and all the other parts required to construct a serial to parallel converter that attaches to the rear of the LCD. Both Modern Device and Wulfden offer such a kit at prices so low that a DIY version may not be worth the effort. Modern Device has now taken their "kit" to a new level by developing an SMD version with almost all the components already soldered on the PCB. The only soldering left for the end user is to install the connectors to attach the LCD, and the kit price is quite a bargain. And as of September 14, 2015, the SMD kit and a 20x4 display are available for about $23, including shipping within the continental USA.
PICAXE, PIC, Arduino, Raspberry Pi, and More
Most (if not all) microcontrollers can use the serial to parallel adapter once the proper baud rate is established. The choices available from Modern Device are 2400, 9600, and 19200; Wulfden adds a 4800 baud model. Baud rates are hard coded in the adapter PIC, so be certain to choose a rate that your microcontroller supports. As a general rule, lower (slower) baud rates are supported by more µCs.
Connection-wise, all that is required are +5V and ground to power the adapter and the LCD, and one available output pin on the µC. The user includes in his/her code the properly formatted instructions to the serial adapter, it does the conversion to parallel, and the message shows up on the LCD. The first time you see it happen, it looks like magic, but it's just the result of good code and a lot of hardware doing its job.
"How do I know how to write my code so the serial adapter will understand what I want?" you might ask. As usual, the answer is in the manual, and both Modern Device and Wulfden supply good documentation. In addition, you can always refer back to the original instructions written by Peter Anderson. Professor Anderson's web site is a treasure trove of information for a variety of microcontrollers and is worth a thorough browse.
Knowing what's going on inside your µC can be made easier by using a character display, and LCD displays are economical, operate on very little power, and are fun to use. A serial to parallel adapter conserves I/Os on your microcontroller and makes it convenient to move the display from one project to another.
PICAXE afficionados are especially encouraged to get a 20x4 display and a serial to parallel adapter that uses Peter Anderson's code. That combination is needed to take full advantage of upcoming PICAXE projects and technical articles from this author here on AAC.