LCD Interfacing using HD44780 Hitachi chipset cmpatible LCD s Mst alphanumeric LCD displays have HD44780 cmpatible driver chipsets that fllw the riginal Hitachi cmmands t cntrl the LCD. The mst cmmn cnnectrs fr alphanumeric LCD s are either 14-pin single rw r 2X7 pins dual rw cnnectrs. Pin Descriptin 1 GND (Grund) 2 Vcc (Supply Vltage) 3 Vee (Cntrast Vltage) 4 R/S (Instructin/Register Select) 5 R/W (Read/Write) 6 E (Clck) 7 D0 (Data0) 8 D1 (Data1) 9 D2 (Data2) 10 D3 (Data3) 11 D4 (Data4) 12 D5 (Data5) 13 D6 (Data6) 14 D7 (Data7) A typical LCD write peratin takes place as shwn in the fllwing timing wavefrm: Page 1
The interface is either a 4-bit r 8-bit parallel bus that allws fast reading/writing f data t and frm the LCD. This wavefrm will write an ASCII Byte ut t the LCD's screen. The ASCII cde t be displayed is eight bits lng and is sent t the LCD either fur r eight bits at a time. If 4-bit mde is used, tw nibbles f data (First high fur bits and then lw fur bits with an E Clck pulse with each nibble) are sent t cmplete a full eight-bit transfer. The E Clck is used t initiate the data transfer within the LCD. 8-bit mde is best used when speed is required in an applicatin and at least ten I/O pins are available. 4-bit mde requires a minimum f six bits. In 4-bit mde, nly the tp 4 data bits (DB4-7) are used. The R/S pin is used t select whether data r an instructin is being transferred between the micrcntrller and the LCD. If the pin is high, then the byte at the current LCD Cursr Psitin can be read r written. If the pin is lw, either an instructin is being sent t the LCD r the executin status f the last instructin is read back (whether r nt it has cmpleted). The HD44780 instructin set is shwn belw: R/S R/W D7 D6 D5 D4 D3 D2 D1 D0 Instructin/Descriptin 4 5 14 13 12 11 10 9 8 7 Pins 0 0 0 0 0 0 0 0 0 1 Clear Display 0 0 0 0 0 0 0 0 1 * Return Cursr and LCD t Hme Psitin 0 0 0 0 0 0 0 1 ID S Set Cursr Mve Directin 0 0 0 0 0 0 1 D C B Enable Display/Cursr 0 0 0 0 0 1 SC RL * * Mve Cursr/Shift Display 0 0 0 0 1 DL N F * * Set Interface Length 0 0 0 1 A A A A A A Mve Cursr int CGRAM 0 0 1 A A A A A A A Mve Cursr t Display 0 1 BF * * * * * * * Pll the "Busy Flag" 1 0 D D D D D D D D 1 1 D D D D D D D D The bit descriptins fr the different cmmands are: "*" - Nt Used/Ignred. This bit can be either "1" r "0" Set Cursr Mve Directin: ID - Increment the Cursr after Each Byte Written t Display if Set S - Shift Display when Byte Written t Display Enable Display/Cursr D - Turn Display On(1)/Off(0) C - Turn Cursr On(1)/Off(0) B - Cursr Blink On(1)/Off(0) Write a Character t the Display at the Current Cursr Psitin Read the Character n the Display at the Current Cursr Psitin Page 2
Mve Cursr/Shift Display SC - Display Shift On(1)/Off(0) RL - Directin f Shift Right(1)/Left(0) Set Interface Length DL - Set Data Interface Length 8(1)/4(0) N - Number f Display Lines 1(0)/2(1) F - Character Fnt 5x10(1)/5x7(0) Pll the "Busy Flag" BF - This bit is set while the LCD is prcessing Mve Cursr t CGRAM/Display A - Address Read/Write ASCII t the Display D - Data Reading Data back is best used in applicatins which required data t be mved back and frth n the LCD (such as in applicatins which scrll data between lines). The "Busy Flag" can be plled t determine when the last instructin that has been sent has cmpleted prcessing. Fr mst applicatins, there really is n reasn t read frm the LCD. The applicatin can write t the LCD and wait the maximum amunt f time fr each instructin (4.1 millisecnds fr clearing the display r mving the cursr/display t the "hme psitin", 160 micrsecnds fr all ther cmmands). Different LCD s execute instructins at different rates and t avid prblems later n (such as if the LCD is changed t a slwer unit), the recmmended maximum delays can be used. Page 3
Befre yu can send cmmands r data t the LCD, the LCD must be initialized. Fr 8-bit mde, this is dne as fllws: 1. Wait mre than 15 msecs after pwer is applied. 2. Write 0x030 t LCD and wait 5 msecs fr the instructin t cmplete 3. Write 0x030 t LCD and wait 160 usecs fr instructin t cmplete 4. Write 0x030 AGAIN t LCD and wait 160 usecs r Pll the Busy Flag 5. Set the Operating Characteristics f the LCD Write "Set Interface Length" Write 0x010 t turn ff the Display Write 0x001 t Clear the Display Write "Set Cursr Mve Directin" Setting Cursr Behavir Bits Write "Enable Display/Cursr" & enable Display and Optinal Cursr In 4-bit mde, the high nibble is sent befre the lw nibble and the E pin is tggled each time fur bits is sent t the LCD. T initialize in 4-bit mde: 1. Wait mre than 15 msecs after pwer is applied. 2. Write 0x03 t LCD and wait 5 msecs fr the instructin t cmplete 3. Write 0x03 t LCD and wait 160 usecs fr instructin t cmplete 4. Write 0x03 AGAIN t LCD and wait 160 usecs (r pll the Busy Flag) 5. Set the Operating Characteristics f the LCD Write 0x02 t the LCD t Enable 4-Bit Mde All fllwing Instructin/Data Writes require tw nibble writes. Write "Set Interface Length" Write 0x01/0x00 t turn ff the Display Write 0x00/0x01 t Clear the Display Write "Set Cursr Mve Directin" Setting Cursr Behavir Bits Write "Enable Display/Cursr" & enable Display and Optinal Cursr Page 4
Cde Example fr 4-bit mde LCD initializatin and displaying a message: main() unsigned char i; /* Initialize the LCD as the very first thing */ InitLCD(); /* Write a simple message t the LCD */ WriteLCD( "Hell" ); vid InitLCD() /* Wait a bit after pwer-up */ delay(200); /* Initialize the LCD t 4-bit mde */ WriteCtrl(3); delay(50); WriteCtrl(3); WriteCtrl(3); WriteCtrl(2); /* Functin Set */ WriteCtrl(2); WriteCtrl(8); /* Display OFF */ WriteCtrl(8); /* Display ON */ WriteCtrl(0x0F); /* Entry mde */ WriteCtrl(6); /* Clear Screen */ Page 5
WriteCtrl(1); delay(100); /* Cursr hme */ WriteCtrl(2); delay(100); vid WriteLCD( unsigned char* message ) unsigned char i; fr( i=0; i<20; i++ ) if(!message[i] ) break; WriteData(message[i]); vid WriteCtrl( unsigned char value ) clrbit(ctrl); WriteCmmn( value ); vid WriteData( unsigned char value ) setbit(ctrl); WriteCmmn( value >> 4 ); WriteCmmn( value ); vid WriteCmmn( unsigned char value ) clrbit(read); value = value & 0x0F; value = value << 4; P0 = P0 & 0x0F; P0 = P0 value; setbit(strobe); delay(1); clrbit(strobe); setbit(read); delay(1); Page 6