Introduction: How to Drive a Character LCD Displays Using DIP Switches

About: Protostack is a supplier of stackable prototyping boards. Our range includes standard breadboard layouts and AVR boards for atmega8, atmega168 and atmega328 development.

 This tutorial will teach you the basics of interfacing with a HD44780 compatible display using some DIP switches and a few other components.

This sort of circuit is a great way to learn how HD44780 displays work.

Step 1: What You Will Need

For this project, you will need

* A Breadboard (http://www.protostack.com/index.php?main_page=product_info&cPath=23&products_id=49)
* A HD44780 compatible LCD display  (http://www.protostack.com/index.php?main_page=product_info&cPath=24_33&products_id=46)
* 9 dip switches (I used an 8 way and a 4 way, but any combination that adds to 9 or greater is OK)
* A micro tactile pushbutton switch (http://www.protostack.com/index.php?main_page=product_info&cPath=22&products_id=23)
* 10 10K Resistors (http://www.protostack.com/index.php?main_page=product_info&cPath=14_31&products_id=37)
* a 100nF capacitor (http://www.protostack.com/index.php?main_page=product_info&cPath=14_28&products_id=19)
* A 1K trimpot
* 16pin header (http://www.protostack.com/index.php?main_page=product_info&cPath=5_9&products_id=32)
* A 5V power source. The protostack 5V power supply kit will do the trick (http://www.protostack.com/index.php?main_page=product_info&cPath=26&products_id=71) but there are many other options too
* Lots of wire (I used cat5)

Step 2: HD44780 Pinout

The photo below shows the pinout for a HD44780 compatible LCD display. These are

  1. VSS - Ground
  2. VCC - (+5V)
  3. VE - Contrast adjustment
  4. RS - Register Select
  5. RW - Read/Write
  6. EN - Clock (Enable)
  7. D0 - Data Bit 0
  8. D1 - Data Bit 1
  9. D2 - Data Bit 2
  10. D3 - Data Bit 3
  11. D4 - Data Bit 4
  12. D5 - Data Bit 5
  13. D6 - Data Bit 6
  14. D7 - Data Bit 7
  15. BLA - Backlight Anode (+)
  16. BLK - Backlight Cathode (-)
The last 2 pins (15 & 16) are optional and are only used if the display has a backlight.

The circuit diagram shows the LCD module with the basic "plumbing" wired up. You will notice that pin 5 (RW) is tied to ground. This pin is use to control whether you are reading or writing to the display. Since reading from the display is uncommon, most people just tie this pin to ground.

The potentiometer connected to pin 3 controls the LCD contrast.

Step 3: The Circuit


The images below show the circuit diagram and the final breadboard layout without the LCD module (this will go on next)

Step 4: Adding the LCD Module

Before we add the LCD module to the breadboard we must solder a 16 pin header to it. I used a 40 pin header (http://www.protostack.com/index.php?main_page=product_info&cPath=5_9&products_id=32) then cut a row of 16 pins off.

Next we insert it into the breadboard and turn the power on.

When you insert the module into the breadboard, you need to be gentle and work the pins in slowly because the pins are a bit thicker than you would normally use with a breadboard.

If you don't see the pattern shown below, you will need to turn the contrast pot till you do. This pattern is the default pattern for an LCD display before initialisation.

Step 5: A Bit of Theory - Sending Data and Commands

Data and commands are sent to the module using the 8 data lines (pins 7-14) and the RS line (pin 4). The RS lines tells the module whether the 8 data bits relate to data or a command. The data/command is read on the falling edge of the enable line (pin 6). This means that when enable transitions from high to low, the values of D0 to D7 and RS are read.

So to send data or a command to the display, you need to
  1. Set Enable to high
  2. Set RS and D0-D7 desired values
  3. Set Enable to low

There are minimum wait times between these operations, but I won't go into them here. You can look these up in the LCD Module Datasheet. (look at the timing diagrams on page 4)

HD44780 based display modules also have a 4 bit interface mode. Under this mode the data or command is transferred to the module using 2, 4 bit nibbles.

Step 6: Reference - Instructions and Characters

This section contains the command a data codes you will need later on

Step 7: Controlling the LCD Using 8 Bit Mode

To interface to the display and output text we need to
  1. Initialise the display,
  2. Set entry mode, and
  3. Send a sequence of characters to display

So to output the text "Hello World" we need to power up the device then enter the following sequence of Data/Commands, pressing Enable at the end of each Data/Command block.

RS   D7 to D0            Description
=======================================================================
0    0 0 1 1 - 1 0 0 0   Function set, 8 bit, 2 lines, 5x7
0    0 0 0 0 - 1 1 1 1   Display ON, Cursor On, Cursor Blinking
0    0 0 0 0 - 0 1 1 0   Entry Mode, Increment cursor position, No display shift
1    0 1 0 0 - 1 0 0 0   H
1    0 1 1 0 - 0 1 0 1   e
1    0 1 1 0 - 1 1 0 0   l
1    0 1 1 0 - 1 1 0 0   l
1    0 1 1 0 - 1 1 1 1   o
1    0 0 1 0 - 0 0 0 0   space 
1    0 1 0 1 - 0 1 1 1   w
1    0 1 1 0 - 1 1 1 1   o
1    0 1 1 1 - 0 0 1 0   r
1    0 1 1 0 - 1 1 0 0   l
1    0 1 1 0 - 0 1 0 0   d

Step 8: Controlling the LCD Using 4 Bit Mode

The main benefit of the 4 bit mode is that less data lines are required. In this mode D3 to D0 are tied to ground and data/commands are transferred 1, 4 bit nibble at a time.

RS   D7 to D0            Description
====================================================================
0    0 0 1 0 - 0 0 0 0   Set to 4 bit operation (note: 1 nibble operation)

0    0 0 1 0 - 0 0 0 0   Function set, 8 bit
0    1 0 0 0 - 0 0 0 0   2nd nibble

0    0 0 0 0 - 0 0 0 0   Display ON, Cursor On, Cursor Blinking
0    1 1 1 1 - 0 0 0 0   2nd nibble

0    0 0 0 0 - 0 0 0 0   Entry Mode, Increment cursor position, No display shift
0    0 1 1 0 - 0 0 0 0   2nd nibble

1    0 1 0 0 - 0 0 0 0   H
1    1 0 0 0 - 0 0 0 0   2nd nibble

1    0 1 1 0 - 0 0 0 0   e
1    0 1 0 1 - 0 0 0 0   2nd nibble

1    0 1 1 0 - 0 0 0 0   l
1    1 1 0 0 - 0 0 0 0   2nd nibble

1    0 1 1 0 - 0 0 0 0   l
1    1 1 0 0 - 0 0 0 0   2nd nibble

1    0 1 1 0 - 0 0 0 0   o
1    1 1 1 1 - 0 0 0 0   2nd nibble

1    0 0 1 0 - 0 0 0 0   space 
1    0 0 0 0 - 0 0 0 0   2nd nibble

1    0 1 0 1 - 0 0 0 0   w
1    0 1 1 1 - 0 0 0 0   2nd nibble

1    0 1 1 0 - 0 0 0 0   o
1    1 1 1 1 - 0 0 0 0   2nd nibble

1    0 1 1 1 - 0 0 0 0   r
1    0 0 1 0 - 0 0 0 0   2nd nibble

1    0 1 1 0 - 0 0 0 0   l
1    1 1 0 0 - 0 0 0 0   2nd nibble

1    0 1 1 0 - 0 0 0 0   d
1    0 1 0 0 - 0 0 0 0   2nd nibble