8 - LCD Interfacing
8 - LCD Interfacing
Interface a 2-line x 20 character LCD module with the built-in HD44780 controller to I/O ports. Two modes of Interfacing: 8bit mode and 4-bit mode LCD displays ASCII characters
Types of LCD
Character LCD Commonly Used with the driver: HD77480 Graphics LCD
Interfacing LCD
Hardware
20 x 2-line LCD displays (two lines with 20 characters per line) LCD has a display Data RAM (registers) that stores data in 8-bit character code. Each register in Data RAM has its own address that corresponds to its position on the line.
PICDEMO
The address range for Line 1 is 00 to 13H and Line 2 is 40H to 53H.
Interfacing LCD
In the 8-bit mode, all eight data lines are connected for data transfer In the 4-bit mode, only four data lines (DB7-DB4 or DB3-DB0) are connected and two transfers per character (or instruction) are needed Instruction Register (IR) to write instructions to set up LCD Data Register (DR) to write data (ASCII characters)
IR REGISTER DR REGISTER
Interfacing LCD
Driver HD77480
RS Register Select (RA3) R/W Read/Write (RA2) E Enable (RA1) Power, ground, and the variable register to control the brightness
Interfacing LCD
LCD Operation
Sets the data line DB7 high as a flag indicating that the controller is busy completing the operation Sets the data line DB7 low after the completion of the operation
The MPU should always check whether DB7 is low before sending an instruction or a data byte After the power up, DB7 cannot be checked for the first two initialization instructions.
Interfacing LCD
Asserts RS low to select IR Reads from LCD by asserting the R/W signal high Asserts the E signal high and then low (toggles) to latch a data byte or an instruction Asserts RS high to select DR Writes into LCD by asserting the R/W signal low Asserts the E signal high and then low (toggles) to latch a data byte or an instruction
Software
Send the initial instructions (commands) before it can check DB7 to set up the LCD in the 4-bit or the 8-bit mode. After the initial commands there are two methods: Use Estimated Delay or Check Flag (Bit D7)
Check DB7 and continue to check until it goes low. Write instructions to IR to set up the LCD parameters such as the number of display lines and cursor status. Write data to display a message.
Command Mode:
Write Command: Before You Write Command Check Flag D7 to See If LCD is ready. Write Command RS = 0 R/W = 0 to Write E or EN = 1 High E = 0 ; High to Low to Latch
Set DB7 as Input Set RS = 0; This is a command operation Set R/W = 1; This is a read operation Set E = 1; High Set E = 0 Low; Wait Until DB7 goes low
First we send the higher nibble and then the lower nibble.
To enable the 4-bit mode of LCD, we need to follow special sequence of initialization that tells the LCD controller that user has selected 4-bit mode of operation:
Wait for about 20mS Send the first init value (0x30) Wait for about 10mS Send second init value (0x30) Wait for about 1mS Send third init value (0x30) Wait for 1mS Select bus width (0x30 - for 8-bit and 0x20 for 4-bit Wait for 1mS
http://www.8051projects.net/lcd-interfacing/commands.php
Graphic LCD