LCD Interfacing To 8051 in 8 bit mode
Written by Amol Shah, on Jun-2008
Views 683

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. Here is a program for interfacing a LCD through 8051 in 8 bit mode.

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.

·         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.

Image
LCD Interfacing to 8051

In this program the controller checks the busy flag & waits till the LCD is busy. 

LCD_RS                      BIT                  P2.5
LCD_RW                     BIT                  P2.6
LCD_E                        BIT                  P2.7
LCD_PORT                 EQU                P0         
ORG 0000h
                                    
            mov a,#38h           
            call lcd_command 
            mov a,#06h
            call lcd_command
            mov a,#0ch
            call lcd_command
            mov a,#01h
            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
/*
Sends whatever data is in the Acc to the LCD as a Command
*/
lcd_command:
            call lcd_ready                          //waits till the LCD is ready
            mov LCD_PORT,a
            clr LCD_RW                                        //we are writing to LCD so RW=0
            clr LCD_RS                                         //Data we are sending is a command so RS=0
            setb LCD_E
            clr LCD_E                                           //LATCH data onto LCD
ret 
/*
Sends whatever data is in the Acc to the LCD to be displayed
*/
lcd_datadisplay:
            call lcd_ready                          //waits till the LCD is ready
            mov LCD_PORT,a
            clr LCD_RW                                        //we are writing to LCD so RW=0
            setb LCD_RS                                       //Data we are sending is a command so RS=0
            setb LCD_E
            clr LCD_E                                           //LATCH data onto LCD
ret  
/*
This subroutine checks the busy flag & waits till LCD is ready to ready for next instruction
*/
lcd_ready:
            mov LCD_PORT,#0ffh
            clr LCD_RS
            setb LCD_RW                                     //we are reading from LCD so RW=1
l1_lcd_ready:
            clr LCD_E
            setb LCD_E
            jb LCD_PORT.7,
           clr LCD_E
ret
END 


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-2008 - visualclinic.fr
License Creative Commons - Some rights reserved
 
< Prev   Next >
Home arrow Code Library arrow LCD Interfacing To 8051 in 8 bit mode