You are on page 1of 7

HD44780 Controlled LCD

http://joshuagalloway.com/lcd.html Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Home
Awards Publications Projects Programs 555 Timer LCD Tutorial PCB Tutorial Links Memoriam ECET Home SPSU Home

HD44780 Controlled LCD

Introduction
LCD' s add a more professional look to most any project as apposed to seven segment or alpha-numeric LED's. Most character LCD's are controlled via an industry standard HD44780-style controller. This is great because almost any character LCD you purchase will operate in the exact same manner. Once you have learned a few subtle nuances of the Hitachi interface, you will be able to easily add attractive output or debugging to any project you try to tackle.

Pin Out
The pin out on most LCD's will be 14 to 16 pins in a single row with the standard 100 mil spacing. The 16 pin version has two extra pins to accommodate a back-light. However, sometimes the pins are present but not connected to anything. I guess this allows the manufacturer to have just one board layout for both models. It's always best to look up a datasheet for your part, but the pin out really is very standardized. Pin 1 2 3 4 5 6 7-14 15-16 Function Ground (Vss), 0V Power (Vdd), +5V Contrast Voltage (usually less than 1V) "R/S" Register Select ( 1 for Data Write, 0 for Command Write) "R/W" Read/Write (1 for Read, 0 for Write) "EN" Enable line (Pulsing high latches a command or data _||_ ) Data Pins (D0-D7) D0 is LSB, in 4-bit mode only D4-D7 are used (Optional) Back-light Anode and Cathode, NC, or Not There at All

Schematics
There are two basic ways to interface the device: 8-bit mode and 4-bit mode. Most often, the "R/W" line is just tied to ground, and the LCD is only written to and not read. The read function is usually used to poll the "Busy Flag" which appears on D7 while the device is incapable of accepting a command (it's busy..get it). However, this function may be ignored by simply waiting the maximum amount of time for each command to complete (most are completed in less than 200us). So, I will only discuss the scenario in which "R/W" is grounded.

8-Bit Interface

1 of 7

11/14/2011 3:29 AM

HD44780 Controlled LCD

http://joshuagalloway.com/lcd.html Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

4-Bit Interface

The 180-ohm resistor going into the Anode pin is to bias the LED back-light on the model I was using when I made this schematic. Your model may not have a back-light, it may need a different value resistor, or you may choose to ignore the back-light all together and save some parts; it's up to you. Also, it isn't shown here, but you should put a 0.1uF or 0.01uF ceramic capacitor near the LCD between Vss and Vdd to act as a filter for high frequency noise.

Writing Data and Commands


In order to write a command or data do the following for both modes: 8-Bit Write Sequence Make Sure "EN" is 0 or low Set "R/S" to 0 for a command, or 1 for data/characters Put the data/command on D7-0 Set "EN" (EN= 1 or High)

2 of 7

11/14/2011 3:29 AM

HD44780 Controlled LCD

http://joshuagalloway.com/lcd.html Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Wait At Least 450 ns!!! Clear "EN" (EN= 0 or Low) Wait 5ms for command writes, and 200us for data writes.

4-Bit Write Sequence Make Sure "EN" is 0 or low Set "R/S" to 0 for a command, or 1 for data/characters Put the HIGH BYTE of the data/command on D7-4 Set "EN" (EN= 1 or High) Wait At Least 450 ns!!! Clear "EN" (EN= 0 or Low) Wait 5ms for command writes, and 200us for data writes. Put the LOW BYTE of the data/command on D7-4 Wait At Least 450 ns!!! Clear "EN" (EN= 0 or Low) Wait 5ms for command writes, and 200us for data writes.

Command Set
R/S R/W D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 * 1 ID S Instruction/Description Clear Display and Home the Cursor Return Cursor and LCD to Home Position Set Cursor Move Direction Enable Display/Cursor Move Cursor/Shift Display Set Interface Length Move Cursor into CGRAM Move Cursor to Display Poll the "Busy Flag" Write a Character to the Display at the Current Cursor Position Read the Character on the Display at the Current Cursor Position

0 1 D C B 1 SC RL * *

0 1 DL N F * * 1 A A A A A A

1 A A A A A A A BF * * * * * * * D D D D D D D D D D D D D D D D

The bit descriptions for the different commands are:


"*" - Not Used/Ignored. This bit can be either "1" or "0" Set Cursor Move Direction: ID - Increment the Cursor After Each Byte Written to Display if Set

3 of 7

11/14/2011 3:29 AM

HD44780 Controlled LCD

http://joshuagalloway.com/lcd.html Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.
S - Shift Display when Byte Written to Display Enable Display/Cursor D - Turn Display On(1)/Off(0) C - Turn Cursor On(1)/Off(0) B - Cursor Blink On(1)/Off(0) Move Cursor/Shift Display SC - Display Shift On(1)/Off(0) RL - Direction of Shift Right(1)/Left(0) Set Interface Length DL - Set Data Interface Length 8(1)/4(0) N - Number of Display Lines 1(0)/2(1) F - Character Font 5x10(1)/5x7(0) Poll the "Busy Flag" BF - This bit is set while the LCD is processing Move Cursor to CGRAM/Display A - Address Read/Write ASCII to the Display D - Data

Initialization
There are, of course, two different ways to initialize the LCD: 4-bit mode, and 8-bit mode. It is interesting to note that a four-line LCD initializes just like a two-line LCD. In fact, the setup is usually just two HD44780-style controllers, but to the user it is transparent. The only weird part is that the lines are addressed such that both of the line 1's precede both line 2's of each controller, which make the addresses non-consecutive. So, if you just set the display to shift the cursor right after each character write, the display will wrap, eventually, from the 1st line to the 3rd line to the 2nd line and, finally, to the 4th line. I will show a general form of how to initialize the display as well as an example. The example will initialize a 2-line (or 4-line, they initialize the same) to shift the cursor right after each character write, display no cursor, and of course turn on the LCD for viewing. Unless explicitly noted "Write" means follow the instructions outlined in the section "Writing Data and Commands." Else an enable pulse is to be provided followed by waiting the stated amount of time. Remember: For commands RS = 0, for data RS = 1 8-Bit Initialization

1 2 3

General Initialization Example Initialization Wait 20ms for LCD to power up Write D7-0 = 30 hex, with RS = 0 Wait 5ms

4 of 7

11/14/2011 3:29 AM

HD44780 Controlled LCD

http://joshuagalloway.com/lcd.html Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

4 5 6 7 8 9 10 11 12

Write D7-0 = 30 hex, with RS = 0, again Wait 200us Write D7-0 = 30 hex, with RS = 0, one more time Wait 200us Write Command "Set Interface" Write 38 hex (8-Bits, 2-lines) Write 08 hex (don't shift display, hide Write Command "Enable Display/Cursor" cursor) Write Command "Clear and Home" Write 01 hex (clear and home display) Write Command "Set Cursor Move Write 06 hex (move cursor right) Direction" -Write 0C hex (turn on display) Display is ready to accept data.

4-Bit Initialization Remember: Data/Command writes of the size one byte are done high-nibble, delay, low-nibble, delay. (1 nibble = 4 bits) General Initialization Example Initialization 1 Wait 20ms for LCD to power up 2 Write D7-4 = 3 hex, with RS = 0 3 Wait 5ms 4 Write D7-4 = 3 hex, with RS = 0, again 5 Wait 200us 6 Write D7-4 = 3 hex, with RS = 0, one more time 7 Wait 200us 8 Write D7-4 = 2 hex, to enable four-bit mode 9 Wait 5ms 10 Write Command "Set Interface" Write 28 hex (4-Bits, 2-lines) Write 08 hex (don't shift display, hide 11 Write Command "Enable Display/Cursor" cursor) 12 Write Command "Clear and Home" Write 01 hex (clear and home display) Write Command "Set Cursor Move 13 Write 06 hex (move cursor right) Direction" 14 -Write 0C hex (turn on display) Display is ready to accept data.

Address Locations
2-Line Display LCD

5 of 7

11/14/2011 3:29 AM

HD44780 Controlled LCD

http://joshuagalloway.com/lcd.html Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

Line 1 Line 2

00 hex, 01 hex, 02 hex,........... 40 hex, 41 hex, 42 hex,...........

4-Line Display LCD 00 hex, 01 hex, 02 hex,........... 40 hex, 41 hex, 42 hex,........... 20 hex, 21 hex, 22 hex,........... 60 hex, 61 hex, 62 hex,...........

Line 1 Line 2 Line3 Line 4

Some Useful Commands


Command (in hex) 0C 08 0E 0F 80 C0 94 D4 Effect Turns ON JUST the LCD, no cursor Turns OFF the LCD display Turns on the LCD display and Sets a SOLID CURSOR Turns on the LCD display and Sets a BLINKING CURSOR Moves cursor to first address on the left of LINE 1 Moves cursor to first address on the left of LINE 2 Moves cursor to first address on the left of LINE 3 Moves cursor to first address on the left of LINE 4

Also, note that adding an offset to the line commands will move the cursor to different places within the line provided you don't exceed the addresses in the line. So, for example, 80h + 2h will move your cursor to the third position of the first line. Most compilers will let you define a string and allow a statement like this: ; LCD Constants LINE1 equ ; ; 8051 code mov lcdRegister, LINE1+2 call writeCommandSubroutine ; or ; PIC code movlw LINE1+2

080h

; or #define LINE1

0x80

; set the register to be passed to the... ; ...subroutine to 3rd spot of 1st line ; write the command

6 of 7

11/14/2011 3:29 AM

HD44780 Controlled LCD

http://joshuagalloway.com/lcd.html Generated by Foxit PDF Creator Foxit Software http://www.foxitsoftware.com For evaluation only.

call

writeCommandSubroutine

; does the same thing for a PIC

Back to Top

7 of 7

11/14/2011 3:29 AM

You might also like