The LCD_HD44780_4BIT accessory library provides a 4-bit parallel interface to a 20x4 character LCD display, based on the Hitachi HD44780 LCD Display controller. This provides a very simple and inexpensive way to add a user interface to any project. These displays are available from several vendors with prices typically ranging from $10-$20. In order to use the parallel interface it is best to purchase a bare display (as shown below), or one with a simple header loaded.
The following files must be included in the project to use the LCD_HD44780_4BIT accessory library:
If the LCD_HD44780_4BIT accessory library is included in a project, the following additional files are also required.
CAUTION: All of the LCD functions contain blocking delays to ensure that critical timing requirements are met. Interrupts are not disabled during these delays, however the application will pause execution until the LCD function call completes.
The following example code is provided to demonstrate the functionality of this library. All examples are presented as main.c files, which are available on GitHub. In order to build the example projects, follow the instructions here for how to create and configure a new project.
Example | Summary Description |
---|---|
LCD Counting Example using 4-bit Interface |
This example demonstrates writing to a 20x4 character LCD module based on the HD44780 display controller using the 4-bit parallel interface mode. The example uses a blocking delay to set the update speed of an 8-bit up-counter which is displayed in decimal, hexadecimal, and binary formats on the LCD. This example can be used to explore display characteristics such as refresh rate. Requires: A 20x4 character LCD display based on the HD44780 controller and the LCD_HD44780_4BIT accessory library files. |
The display images shown at the top of this page are of the Cofufu 20x4 Black on Green LCD module from Amazon. This particular display comes with headers and 10k potentiometers to implement the contrast adjustment. If a white on blue version is desired one can be found at AdaFruit that also comes with a header and potentiometer. Typically if you order a display with a header and potentiometer, you will receive a bare display. If you order what appears to be a bare display by itself, you may find that the order is "upgraded" to include a free I2C daughter card already attached to the display. This can be annoying if what you wanted was in fact a bare display. The Cofufu is my go-to display for these applications.
The most common LCD backlight options are either Black on Yellow/Green or White on Blue (both are shown below). The choice of one versus the other is primarily one of aesthetics, but there are some things to consider. The white on blue has a "softer" look to it than the Black on Yellow/Green which can be a little "glaring". However, the Black on Yellow/Green has several advantages over the White on Blue displays. Both LCDs have a fairly slow refresh rate which produces a "ghosting" effect that lasts a little after each update, however this is more noticeable on the White on Blue displays. The viewing angle on the Black on Yellow/Green is much better, making it possible to read the display from the sides much farther than with the White on Blue displays. The Black on Yellow/Green displays are also far less dependent on the backlight for readability, which makes it much easier to fine tune the backlight level. In fact, if the backlight breaks on the White on Blue display, it becomes useless.
Most of the LCD displays appear to be based on the 2004A LCM module, but there are a lot of inconsistencies between displays that appear to be either vendor-specific or just time-dependent. Either way it is possible that you may receive a display with different current limiting resistors, or possibly no current limiting at all! Always check the value of these resistors before applying power! If power is applied to a module with no current limiting, the backlight will be destroyed. The resistance between the "A" (Anode) and "K" (Kathode) input pins and the backlight connections should generally be around 51-68 ohms. You won't be able to measure directly between A and K, but will have to follow the path between the A and K pins to the backlight pins.
A picture is shown of the current limiting resistors on one example module. The resistors may be located differently depending on LCM revision. In this example, there are two resistors (R8 and R9) which are each in series with one of the backlight pins. The total resistance being the series combination of both values. The resistors are 1206 size (a short-hand code for having a length and width of 0.125" x 0.06") and are marked with "0" and "510". The "0" is a special designator for a jumper that provides no resistance. The "510" is a 3-digit code for standard parts, where the first 2 digits define the base resistance and the final digit defines the number of zeroes to be added to the base value (Or for a code "XXY", you could think of it as XX * 10^Y). In this case "510" = 51 ohms (51 + no zeroes).
The LCD backlight connections are intended to be connected to a +5V source (A=+5V, K=GND), however both the Yellow/Green and Blue backlights will function at +3.3V which is also available on the MSP430F5529LP board. This can provide a less harsh and glaring look in the case of Yellow/Green, and a less washed out look for Blue. The example photos above were both taken with a backlight connection to +3.3V, which operates the backlights at ~10 mA as opposed to ~40 mA when connected to a 5V supply.
The following tables provide measured values of backlight current and backlight voltage when supply voltages between 3V-5.5V were applied to the A-K pins. Both of the boards used for data collection had a 51 Ohm current limiting resistor installed. This affects the amount of current obtained for a given A to K voltage applied, however the backlight voltage to current relationship is unaffected.
     Also provided below is the regression fit of the IV relationship for the Yellow/Green and Blue backlights.