HD44780 Compatible LCDs library

Alphanumeric LCDs are interesting in some small applications to display few information to the user. The HD44780 Compatible LCDs are chip and easy to use on all microcontrollers, this make them very popular. Several models exist with 1 to 4 lines, 8 to 40 columns, usually with a green or blue background and sometimes with an additional backlight.

This pages proposes a simple HD44780 Compatible LCDs library based on the following shield.

You can download the full article and source codes using the following link:

HD44780 Compatible LCDs library - Revision 1.0, 2015-08-13

1. Wiring

The pinout of the HD44780 Compatible LCDs is usually the following.

Pin Name Description
1 GND Ground
2 VCC 5 volts power supply
3 Vo Contrast adjustment
4 RS Register Select pin, used to transmit command (RS=0) or data (RS=1)
5 R/W Read/Write pin, used to read (R/W=1) or write (R/W=0) command or data
6 E Enable pin, active on low edge
7-14 D0-D7 Data bus
15 A Anode of the backlight (optional)
16 K Cathode of the backlight (optional)

The HD44780 Compatible LCDs can be used in two different modes:

- 4-bits mode, using only pins D4 to D7 of the data bus - simplify wiring but require a little bit more complex software;
- 8-bits mode, using all pins of the data bus - simplify the software but require more wiring.

All functionalities are available in both configurations. The following schemas illustrate 4-bits and 8-bits modes.

It is possible to tie R/W pin to the ground to free a pin on the microcontroller. In this case, some few functionalities are not available, but the LCD can still be used. Thus, the minimal configuration to drive the LCD requires only 6 pins (using 4-bits mode with RS, E and D4 to D7 pins).

The shield chosen to develop this library is wired in 4-bits mode with R/W pin tied to the ground.

2. Software

The architecture of the software is described below.

The library is written according to the communication specifications of the HD44780 Compatible LCDs (a description is available in the full article).

The following functions are available:

- HD44780_Init: initialize microcontrollers pins and LCD in 4-bits mode;
- HD44780_Clear: clear the screen and set DDRAM address to 0;
- HD44780_ReturnHome: set DDRAM address to 0;
- HD44780_Goto: go to a specific line and column;
- HD44780_WriteCharacter: write a single character at the current location;
- HD44780_WriteString: write a string (must be null terminated) at the current location;
- HD44780_SetBacklight: control the backlight of the LCD;
- HD44780_SetDisplay: control the display of the LCD;
- HD44780_SetCursor: control cursor and blinking character;
- HD44780_SetSpecialCharacter: used to define special characters.

The size of the LCD, the wiring and other parameters can be modified in the library to match your own application.


This simple library will be useful to use any HD44780 Compatible LCD in your projects.