LCD Interfacing To 8051 in 4bit mode
Written by Amol Shah, on Jul-2008
Views 1264    

Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as for debugging purpose. The most common type of LCD controller is HITACHI 44780 which provides a simple interface between the controller & an LCD. These LCD's are very simple to interface with the controller as well as are cost effective.

The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The number on data lines depends on the mode of operation. If operated in 8-bit mode then 8 data lines plus 3 control lines i.e. total 11 lines are required.

In case of 4-bit mode only 4 data lines are required & the 8-bit data is sent by first sending the higher nibble followed by the lower nibble. Since we are operating the LCD in 4 bit mode only 7 port pins are required. Here is a program for interfacing a LCD through 8051 in 4 bit mode. The Higher 4 bits of P0 are connected to the higher 4 bits of the LCD i.e. P0.4 – P0.7 are connected to D4 – D7.

Image

The three control lines are RS, RW & Enable.

·         RS: Register Select. When RS = 0 the command register is selected. When RS=1 the data register is selected.

·         RS: Register Select. When RS = 0 the command register is selected. When RS=1 the data register is selected.

·         RW: Read or Write. When RW=0 write to LCD. When RW=1 read from LCD.

·         Enable: Used to Latch data into the LCD. A HIGH TO LOW edge latches the data into the LCD. 

LCD_RS                 BIT                          P2.5

LCD_RW               BIT                          P2.6

LCD_E                   BIT                          P2.7

LCD_PORT           EQU                        P0                 //the higher nibble i.e. P0.4 - P0.7 is used

 

ORG 0000h         

                mov a,#20h

                call lcd_command

                mov a,#28h

                call lcd_command

                mov a,#06h

                call lcd_command

                mov a,#01h

                call lcd_command

                mov a,#0ch

                call lcd_command

                                 

                mov a,#86h                                                                                       

                call lcd_command                                            //1st line 6th character

                mov a,#'D'

                call lcd_datadisplay

                mov a,#'N'

                call lcd_datadisplay

                mov a,#'A'

                call lcd_datadisplay

               

                mov a,#0c3h

                call lcd_command                                            //2nd Line 3rd character

                mov a,#'T'

                call lcd_datadisplay

                mov a,#'E'

                call lcd_datadisplay

                mov a,#'C'

                call lcd_datadisplay

                mov a,#'H'

                call lcd_datadisplay

                mov a,#'N'

                call lcd_datadisplay

                mov a,#'O'

                call lcd_datadisplay

                mov a,#'L'

                call lcd_datadisplay

                mov a,#'O'

                call lcd_datadisplay

                mov a,#'G'

                call lcd_datadisplay

                mov a,#'Y'

                call lcd_datadisplay

               

loop:

                ajmp loop

               

               

 

lcd_command:                                  

                mov b,a

                call lcd_ready

                clr lcd_rw

                clr lcd_rs

                orl lcd_port,#0f0h

                mov a,b

                orl a,#0fh

                anl lcd_port,a

                setb lcd_e

                clr lcd_e

 

                orl lcd_port,#0f0h

                mov a,b

                swap a

                orl a,#0fh

                anl lcd_port,a

                setb lcd_e

                clr lcd_e

                ret

  

lcd_datadisplay :

                mov b,a

                call lcd_ready

                clr lcd_rw

                setb lcd_rs

                orl lcd_port,#0f0h

                mov a,b

                orl a,#0fh

                anl lcd_port,a

                setb lcd_e

                clr lcd_e

 

                orl lcd_port,#0f0h

                mov a,b

                swap a

                orl a,#0fh

                anl lcd_port,a

                setb lcd_e

                clr lcd_e

                ret

lcd_ready:

                clr lcd_e

                orl lcd_port,#0f0h

                clr lcd_rs

                setb lcd_rw

                setb lcd_e

                mov a,lcd_port

                clr lcd_e

                anl a,#0f0h

                mov temp,a

 

                orl lcd_port,#0f0h

                setb lcd_e

                mov a,lcd_port

                clr lcd_e

                anl a,#0f0h

                swap a

                orl a,temp

                jb acc.7,lcd_ready

                ret



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!
Quote this article in website Favoured Print Send to friend Related articles Save this to del.icio.us

Users' Comments (0) RSS feed comment

No comment posted

Add your comment



mXcomment 1.0.5 © 2007-2009 - visualclinic.fr
License Creative Commons - Some rights reserved
 
< Prev   Next >
Home arrow Code Library arrow LCD Interfacing To 8051 in 4bit mode