8051 Interfacing with display sevices MICROCONTROLLER AND ITS APPLICATIONS Rahul Salgo LCD Interfacing To 8051 in 8 bit mode Liquid Crysta l Display also called as LCD is very helpful in providing user interface as well as fordebuggin g purpose. The most common type ofLCD co nt roll er is HIT ACHI 44780 whic h provides a simple interfac e between the controller& an LCD. These LCD' s ar e ve ry si mple 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 de pe nds on the mode of oper at io n. 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 regis ter 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 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 charactermov 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 charactermov 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'
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Liquid Crystal Display also called as LCD is veryhelpful 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 tointerface with the controller as well as are costeffective.
The LCD requires 3 control lines (RS, R/W &EN) & 8 (or 4) data lines. The number on datalines depends on the mode of operation. If operated in 8-bit mode then 8 data lines plus 3control lines i.e. total 11 lines are required. Here is
a program for interfacing a LCD through 8051 in8 bit mode.
The three control lines are RS , RW & Enable.
RS: Register Select. When RS = 0 thecommand register is selected. When RS=1 thedata register is selected.
RW: Read or Write. When RW=0 writeto LCD. When RW=1 read from LCD.
Enable: Used to Latch data into the LCD.A HIGH TO LOW edge latches the data into theLCD.
LCD Interfacing to 8051
In this program the controller checks the busy flag& waits till the LCD is busy.
LCD_RS BIT P2.5LCD_RW BIT P2.6LCD_E BIT P2.7LCD_PORT EQU P0ORG 0000h
/*Sends whatever data is in the Acc to the LCD as aCommand*/lcd_command:
call lcd_ready //waits tillthe LCD is ready
mov LCD_PORT,aclr LCD_RW //weare writing to LCD so RW=0
clr LCD_RS//Data we are sending is a command so RS=0
setb LCD_Eclr LCD_E
//LATCH data onto LCDret/*Sends whatever data is in the Acc to the LCD to
be displayed*/lcd_datadisplay:
call lcd_ready //waits tillthe LCD is ready
mov LCD_PORT,aclr LCD_RW //we
are writing to LCD so RW=0setb LCD_RS
//Data we are sending is a command so RS=0setb LCD_E
clr LCD_E//LATCH data onto LCDret/*This subroutine checks the busy flag & waits tillLCD is ready to ready for next instruction*/lcd_ready:
mov LCD_PORT,#0ffhclr LCD_RSsetb LCD_RW //we
are reading from LCD so RW=1l1_lcd_ready:
clr LCD_Esetb LCD_E
jb LCD_PORT.7,clr LCD_E
retEND
Interfacing with 7-SEGMENT
The seven segment display is one of the commonlyused display devices in the world of electronics.Easy of operation and good visual indication hasmade their use in low cost circuits e.g. counter andspeedometer and even in costly devices e.g. power system static protective relays. Seven segmentdisplay is a great utility at low cost.
Seven segment display is collection of seven led.
In a simple LED package, each LED is typically
connected with one terminal to its own pin on the
outside of the package and the other LED terminal
connected in common with all other LEDs in the
device and brought out to a shared pin. This shared
pin will then make up all of the cathodes (negative
terminals) OR all of the anodes (positive terminals)
of the LEDs in the device; and so will be either a
In early days to drive the seven segment decoder was used with it and the BCD was send to thedecoder IC. But the microcontroller has eliminated
the use of decoder as already decoded data is sentto the seven segment display.
Common anode display are most suitable for interfacing with 8051 since 8051 port pins can sink current better than sourcing it.
Connect the a to g pins and dot pin of sevensegment display to the 8-bit port of microcontroller
Now send the respective hex data to display
specific number on seven segment display on that port.
Give some delay and repeat the process if you
want to display another digit.
Circuit Diagram
Note: Change the value of resistor to obtainrequired contrast.
Timer Interrupt Based LED Blinking Program
Here is a simple code for Blinking a LED. TheLED is connected to P2.0 & 12MHz crystal isused. The Anode of the LED is given to Vcc
through a resistor & the cathode is connected tothe microcontroller pin. Please check this link tosee how to interface LED to Microcontroller. TheLED is ON for One Second & OFF for ONESecond.
Here we will be using Timer 0 in 16 bitINTERRUPT mode to generate One second delay.We load TH0 & TL0 with a specific value & onevery clock cycle TH0 & TL0 increments by 1and when the TIMER overflows from FFFF to
0000 a Timer0 overflow flag is set & interrupt isgenerated. The maximum delay that can begenerated using TIMER 0 in any mode is 65535clock cycles & since we are using 12MHz crystalthe maximum delay is 65.535ms. But we require1second delay. So we generate 50ms delay usingTIMER 0 & when 20 such delays have beengenerated we come to know that one second haselapsed. So basically 0.05ms X 20 =1 second. Sowe use a RAM location “multiplier ” load it with20 and whenever the timer overflows the ram
location multiplier is decremented by one. Thuswhen multiplier becomes zero we come to knowthat one second has elapsed & we toggle the LED.
Here is a simple code for Blinking a LED. TheLED is connected to P2.0 & 12MHz crystal isused. The Anode of the LED is given to Vccthrough a resistor & the cathode is connected tothe microcontroller pin. Please check this link tosee how to interface LED to Microcontroller. TheLED is ON for One Second & OFF for ONESecond. This delay of ONE Second can bechanged by changing the values loaded into the
R7, R6 and R5 in the delay subroutine. The higher the value loaded the higher the delay. Since thecontroller is 8 bit microcontroller values greater than 255 cannot be loaded.
led1 bit P2.0 ORG 0000hloop:
clr led1 //TURNON LED
call delaysetb led1 //TURN
OFF LEDcall delayajmp loop
delay:mov r7,#200
l1_delay:mov r6,#217
l2_delay:
mov r5,#10djnz r5,$ // "$" over
here indicates jump at the same locationdjnz r6,l2_delaydjnz r7,l1_delayret
end
Timer Based Led Blinking Program
Here is a simple code for Blinking a LED. TheLED is connected to P2.0 & 12MHz crystal isused. The Anode of the LED is given to Vcc
through a resistor & the cathode is connected tothe microcontroller pin. Please check this link tosee how to interface LED to Microcontroller. TheLED is ON for One Second & OFF for ONESecond.
Here we will be using Timer 0 in 16 bit mode togenerate One second delay. The maximum delaythat can be generated using TIMER 0 in any modeis 65535 clock cycles & since we are using12MHz crystal maximum delay is 65.535ms. Butwe require 1second delay. So we generate 50msdelay using TIMER 0 & when 20 such delayshave been generated we come to know that onesecond has elapsed. So basically 0.05ms X 20 =1second. So we use a RAM location “multiplier ”load it with 20 and whenever the timer overflowsthe ram location multiplier is decremented by one.
Thus when multiplier becomes zero we come toknow that one second has elapsed & we toggle theLED.