Embedded Search

Saturday, December 30, 2006

LCD interfacing with PIC16F877A

The purpose of this article is to give a brief tutorial on how to interface PIC16F877A with Hitachi 44780-Based LCD.






Click here for LCD data sheet
The most common used for the 44780-based LCD is 16 pin in a row. The pins assignment is listed in Table 1.0.

Table 1.0 Hitachi 44780 Based LCD Pinout
Pin Description
1 Vss, Ground
2 Vcc, +5V supply
3 Vee, Contrast Voltage
4 R/S, Instruction / Data Mode select
5 R/W, Read / write
6 E, Enable
7-14 D0-D7 Data lines
15 +Led
16 -Led

The hardware setup is shown in Figure 1.0












Figure 1.0

The LCD requires 3 "control" lines from the microcontroller.

Enable (E)
This line allows access to the display through R/W and RS lines. When this line is low, the LCD is disabled and ignores signals from R/W and RS. When (E) line is high, the LCD checks the state of the two control lines and responds accordingly.
Read/Write (R/W)
This line determines the direction of data between the LCD and microcontroller. When it is low, data is written to the LCD. When it is high, data is read from the LCD.
Register select (RS)
With the help of this line, the LCD interprets the type of data on data lines. When it is low, an instruction is being written to the LCD. When it is high, a character is being written to the LCD.

The instructions available for 44780 Hitachi LCD is shown in Table 2.0

Table 2.0












The LCD module needs to be initialized before you can send command or data to it. The initialization steps is listed below:

1 Wait for about 45ms delay after power is applied
2 Clear RS and R/W to select instruction mode and writing mode
3 Write the instruction set to set the interface to 8bit, 2 line and 5x7 dot
i.e. write b’00111011’ to LCD.
4 Set the Enable line then wait for 5ms for the instruction to complete.
5 Write the same data, b00111011 to LCD and wait >160us for instruction to complete
6 Write the same data again, b00111011 to LCD and wait >160us for instruction to complete
7 Set the operating Characteristics of the LCD
- Write 0x08 to turn off the display, set E = 1 for 3us
- Delay 50us
- Write 0x01 to clear the display, set E = 1 for 3us
- Delay 1.8ms
- Write 0x02 for cursor home, set E = 1 for 3us
- Delay 1.8ms
- Write 0x0F to turn on the display, set E = 1 for 3us
- Delay 50us
- Write 0x06 for entry mode set, set E = 1 for 3us
- Delay 50us
8 Set RS to 0, and R/W to 0


After the LCD initialization, now is ready to send the characters to display in the LCD. Follow the steps below to write data/character to LCD:

1) Set RS to 1 for character mode
2) Clear R/W to select writing mode.
3) Set the character code (refer to Table 4.0) to data line.
4) Set E = 1 for 3us, then E = 0.
5) Wait for at least 160us
6) Repeat step 3 for the next character.

2 comments:

Nimish Dave said...
This comment has been removed by the author.
Nimish Dave said...

Good Work
PIC16F877A microcontroller connection with HD44780 LCD,C code for programming PIC16F877A to interface LCD
www.lcdinterfacing.info/Interface-LCD-PIC16F877A.php