Home > AVR Microcontroller Projects > Interfacing a HD44780 Based LCD to an AVR

Interfacing a HD44780 Based LCD to an AVR

This document describes how to interface a Hitachi HD44780 based character LCD module to an AVR using the memory-mapped mode or the 4-bit IO port mode.

The most common type of controller used by character LCD modules is the Hitachi HD44780, which uses a relatively simple interface between the microcontroller and an LCD.

Most 44780 based LCD's use a connector with 14 pins in a row. The pins are wired as:

Pins Signal Description
1 Ground 0V
2 Vcc +5V
3 Contrast Voltage  
4 R/S Register Select 0=Instruction Register. 1=Data
5 R/W Read/Write LCD 1=Read from LCD, 0=Write to LCD
6 E Clock 450 nsecs positive pulse to initiate data transfer
7 - 14 Data I/O Pins 8-bit data bus (4-bit mode only uses pins 11..14)

The interface to the LCD is a parallel bus, which allows easy interfacing to an microcontroller.

 

Interface using memory-mapped mode

Connecting the LCD to an AVR which support external SRAM mode (e.g. AT90S8515, ATMega) is easy and allows to access the LCD module using simple read/write instructions.

The HD44780 controller uses Motorola compatible signal timing using R/W and Enable signals, which is different from the Intel compatible RD, WR signals used be the AVR.

The main difference is that the data transfer to/from the LCD controller is initiated using a single Enable pulse, the read or write mode must be selected before with the R/W signal. The AVR uses separate signals to initiate read or write data transfers. The RD signal is used to initiate a read from the external device, while the WR signal initiates a write to an external device.

The following interface circuit shows how a LCD module can be connected to an AVR using the memory-mapped mode:

LCD interface circuit (11449 bytes)

The Enable pulse is generated from the RD/WR signals and address line A15. Since the R/W signal must be applied before the Enable signal, it cannot be derived from the RD/WR signals. Therefore address line A8 is used to select read/write mode.

Using the above circuit, the following addresses must be used to access the LCD:

Mode LCD register Address
write LCD data register 0xC000
write LCD instruction register 0x8000
read LCD data register 0xC100
read LCD instruction register 0x8100

Difference to the STK200 LCD interface
The LCD interface used by the STK200 starter kit generates the Enable signal using a capacitor, resistor and diode, which has the disadvantage that it only works with a 4Mhz crystal. My circuit uses less components and is independent of the CPU clock.

Software
My LCD library for the AVR-GCC compiler can be configured to operate in the memory-mapped mode, when the constant LCD_IO_MODE is 0 in the include file lcd.h.

 

Interface using the 4-bit Mode

The HD44780-based LCD unit can also be operated in the 4-bit mode. In this mode data is exchanged with the LCD module using two four bit nibbles. The correct timing of the control signals is generated by software, therefore any AVR with at least seven free I/O pins can be used.

starterkit-lcd-4bit.gif (10099 bytes)

My LCD library for the AVR-GCC compiler also supports the 4-bit IO mode when the constant LCD_IO_MODE is defined as 1 in the include file lcd.h.

 

Copyright 2003 Peter Fleury http://tinyurl.com/peterfleury