This page describes how to connect a LCD-Display to a AVR-microcontroller. The example is based on a LCD module with the Hitachi HD44780 LCD-controller.You can get these displays in various kinds, from 1 to 4 lines and from 8 to 40 characters per line.
A display with 16 characters per line and 2 lines is used in this example. The display uses a power supply of 5V DC. Connecting of the display to the AVR-microcontroller is easy.
The display module has 8 data lines and 3 control lines. The 8 data lines are used to send data or instructions to the module. Instructions that can be send to the display are for example clearing the display or set the cursor. The control lines are of course used to control the display.
The 8 data lines can be used as a 4-bit bus or as a 8-bit bus. In the 4-bit bus mode the data and instructions are send by 2 groups of 4 bits after each other so the program code will be more then when the 8-bits bus is used. In this example the 4-bits bus is used, this saves 4 connections and because of that the display can be controlled by only one 8-bit port of the AVR microcontroller.
The line Enable controls the display. If it is high the data on data bus is put in the register of the display. If the line is low all the data lines are tri-state, what means that they are not connected to the microcontroller. You can see this as a switch that is open.
The line Read/Write enables reading from or writing to the display. If the R/W signal is low data can be written to the display, if it is high data can be read from the display. This is useful if you want to know if the module is ready to recieve new data.
The line Register Select selects if the data send to the display are instructions for the display or characters that have to be shown on the display.
In the table below you can see the pin assignment of the LCD module
In the table below you can see how the LCD module is connected to the AVR-microcontroller.Because the display is used in the 4-bit mode, 4 lines of the data bus are not connected.The signal R/W has to be connected to GND so the display is always in the write mode. The pins 15 and 16 are used to connect the supply for the LED-backlight of the display, if it is present at the module. If you use 5V DC you need to place a resistor to limit the current. With a trimpotmeter of 10K connected at pin 3 (VO) of the display the contrast can be set.
Below is the schematic that shows you how to connect the LCD to the AVR microcontroller via a 10 pole flatcable with a 10 pin connector. The 10 pin connector can be plugged into the 10 pin header of the STK500 Board or the ATTiny2313 Board.
You can buy the ATTiny2313 Board at www.bizztronix.eu
The LCD module connected to the AT2313 Project Board.
To control the display you can use BASCOM or Assembler. BASCOM has special commands for configuring and driving a LCD Display. In the table below you see the LCD commands and their functions.
To control the LCD display you need to implement the instructions in your program code. First you have to configure the display, which type of display you use (number of lines and number of characters on a line), to which pins of the microcontroller the lines of the LCD module are connected and which mode you use, 4-bit mode or 8-bit mode (default is 4-bit mode). Below is an example program of how to write text to the LCD display.