hd44780 Character LCD Displays – Part 2 Using Atmega

LCD Displays Part 2

Introduction

This tutorial continues from Character LCD Displays – Part 1. In this part we will connect the LCD module to an Atmega8 microcontroller, then write some code to drive it.

LCD Displays Part 2

The Circuit

Our first task is to build the circuit.
We will be using an AVR 28 pin Development Board. For the power supply we will use a USB to DC Barrel plug cable, so we won’t need to build a 5V regulator circuit. Instead we will run a wire from the barrel connector to the positive power rail, as shown in the photo below.
Also we won’t need an external crystal or AVCC filter block. We still need to run power to AVCC and this is done with a piece of wire.
Because we want the ability to remove the LCD module later, we will solder a 16 pin female header to the board.
Next we wire-up VDD and BLA to the positive power rail along with VSS, RW, D0, D1, D2, D3 and BLK to the ground power rail. D0 to D3 are being tied to ground because we will drive the display in 4 bit mode. This lets us drive the display with just 6 I/O lines.

Next we add a trimpot for the LCD contrast. I used a 5K pot, but a range of other values would work as well.
We now connect RS, EN and D4-7 to PC0-PC5. These could have been connected to any of the atmega8 I/O ports, but port C seemed to be ideal as it has 6 usable I/O pins. If you decide to use other pins just change the source code accordingly.

LCD Displays -Part 2 Schematic

Coding

The previous example is fine, if all you want to do is understand the principles of how LCD displays are driven, but in practice coding in this manner is a bit painful. To make things easier we need to abstract away the finer implementation details and focus on the operations the developer needs to perform. The easiest way to do this is use a pre-existing library.

A very popular HD44780 AVR library is Peter Fleury’s LCD library. This library is very good but I’m going to use alank2’s slimmed down LCD library instead. My reasons are:

  • Peter’s library requires that R/W be connected to one of the I/O ports
  • alank2’s library separates out settings into a separate .h file. I think this is a lot cleaner
  • alank2’s library compiles a bit more tightly
  • alank2’s library supports up to 4 LCD displays, each sharing the same data and RS lines, but having different EN lines.

Read More: hd44780 Character LCD Displays – Part 2

 

Leave a Comment

Your email address will not be published. Required fields are marked *