How to Drive a Character LCD Displays Using DIP Switches
by protostack in Circuits > Electronics
85708 Views, 88 Favorites, 0 Comments
How to Drive a Character LCD Displays Using DIP Switches
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.
What 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)
HD44780 Pinout
- VSS - Ground
- VCC - (+5V)
- VE - Contrast adjustment
- RS - Register Select
- RW - Read/Write
- EN - Clock (Enable)
- D0 - Data Bit 0
- D1 - Data Bit 1
- D2 - Data Bit 2
- D3 - Data Bit 3
- D4 - Data Bit 4
- D5 - Data Bit 5
- D6 - Data Bit 6
- D7 - Data Bit 7
- BLA - Backlight Anode (+)
- BLK - Backlight Cathode (-)
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.
The Circuit
The images below show the circuit diagram and the final breadboard layout without the LCD module (this will go on next)
Adding the LCD Module
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.
A Bit of Theory - Sending Data and Commands
So to send data or a command to the display, you need to
- Set Enable to high
- Set RS and D0-D7 desired values
- 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.
Reference - Instructions and Characters
Controlling the LCD Using 8 Bit Mode
- Initialise the display,
- Set entry mode, and
- 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
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