Вы находитесь на странице: 1из 5

8051 Interfacing with display sevices

MICROCONTROLLER AND ITS APPLICATIONS

Rahul Salgo
LCD Interfacing To 8051 in 8 bit mode 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. LCD Interfacing to 8051 In this program the controller checks the busy flag & waits till the LCD is busy. LCD_RS LCD_RW LCD_E LCD_PORT ORG 0000h BIT BIT BIT EQU P2.5 P2.6 P2.7 P0

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 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 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' //1st

//2nd

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

Interfacing with 7-SEGMENT

The seven segment display is one of the commonly used display devices in the world of electronics. Easy of operation and good visual indication has made their use in low cost circuits e.g. counter and speedometer and even in costly devices e.g. power system static protective relays. Seven segment display 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 "Common Cathode" or "Common Anode" device

depending how it is constructed.

want to display another digit. Circuit Diagram

How to display digits on seven segment display Apply proper polarity to common pin. Make the required segment pin low or high depending on the type of display. You can refer the table given below to send respective hex value for displaying numbers from 0 to 9. Note: Change the value of resistor to obtain required contrast. Timer Interrupt Based LED Blinking Program Here is a simple code for Blinking a LED. The LED is connected to P2.0 & 12MHz crystal is used. The Anode of the LED is given to Vcc through a resistor & the cathode is connected to the microcontroller pin. Please check this link to see how to interface LED to Microcontroller. The LED is ON for One Second & OFF for ONE Second. Here we will be using Timer 0 in 16 bit INTERRUPT mode to generate One second delay. We load TH0 & TL0 with a specific value & on every clock cycle TH0 & TL0 increments by 1 and when the TIMER overflows from FFFF to 0000 a Timer0 overflow flag is set & interrupt is generated. The maximum delay that can be generated using TIMER 0 in any mode is 65535 clock cycles & since we are using 12MHz crystal the maximum delay is 65.535ms. But we require 1second delay. So we generate 50ms delay using TIMER 0 & when 20 such delays have been generated we come to know that one second has elapsed. So basically 0.05ms X 20 =1 second. So we use a RAM location multiplier load it with 20 and whenever the timer overflows the ram location multiplier is decremented by one. Thus when multiplier becomes zero we come to know that one second has elapsed & we toggle the LED.

Interfacing seven segment microcontroller

display

to

In early days to drive the seven segment decoder was used with it and the BCD was send to the decoder IC. But the microcontroller has eliminated the use of decoder as already decoded data is sent to 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 seven segment 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

led1 P2.0 multiplier 30h MULTIPLIER_DEFAULT 20 ORG 0000h ajmp main ORG 000bh jmp timer0_interrupt Interrupt Subroutine main:

BIT EQU DATA ret end

pop b pop acc

Delay Based LED Blinking Program Here is a simple code for Blinking a LED. The LED is connected to P2.0 & 12MHz crystal is used. The Anode of the LED is given to Vcc through a resistor & the cathode is connected to the microcontroller pin. Please check this link to see how to interface LED to Microcontroller. The LED is ON for One Second & OFF for ONE Second. This delay of ONE Second can be changed 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 the controller is 8 bit microcontroller values greater than 255 cannot be loaded. led1 bit P2.0

// Jump To

setb EA //Enable Interrupt setb ET0 //Enable timer 0 Interrupt mov multiplier,#MULTIPLIER_DEFAULT mov TMOD,#01h Timer 0 Mode 1(16 bit mode) mov TH0,#3ch //0.05 mov TL0,#0B0H setb TR0 clr led1 loop: ajmp loop

// sec

//Start Timer 0

timer0_interrupt: push acc push b push psw push dph push dpl clr TF0 clr TR0 //Stop Timer mov TH0,#3ch //0.05 sec mov TL0,#0B8H //Reload Timer djnz multiplier,c1_timer0_interrupt mov multiplier,#MULTIPLIER_DEFAULT cpl led1 c1_timer0_interrupt: setb TR0 //Start Timer 0 pop dpl pop dph pop psw

ORG 0000h loop: clr led1 ON LED call delay setb led1 OFF LED call delay ajmp loop delay: mov r7,#200 l1_delay: mov r6,#217 l2_delay:

//TURN //TURN

mov r5,#10 djnz r5,$ // "$" over here indicates jump at the same location djnz r6,l2_delay djnz r7,l1_delay ret end Timer Based Led Blinking Program Here is a simple code for Blinking a LED. The LED is connected to P2.0 & 12MHz crystal is used. The Anode of the LED is given to Vcc

through a resistor & the cathode is connected to the microcontroller pin. Please check this link to see how to interface LED to Microcontroller. The LED is ON for One Second & OFF for ONE Second. Here we will be using Timer 0 in 16 bit mode to generate One second delay. The maximum delay that can be generated using TIMER 0 in any mode is 65535 clock cycles & since we are using 12MHz crystal maximum delay is 65.535ms. But we require 1second delay. So we generate 50ms delay using TIMER 0 & when 20 such delays have been generated we come to know that one second has elapsed. So basically 0.05ms X 20 =1 second. So we use a RAM location multiplier load it with 20 and whenever the timer overflows the ram location multiplier is decremented by one. Thus when multiplier becomes zero we come to know that one second has elapsed & we toggle the LED. led1 P2.0 multiplier 30h BIT EQU //RAM Location

jnb TF0,$ wait for timer to over flow clr TF0 clear TIMER 0 flag clr TR0 /Stop Timer 0 mov TH0,#3ch 05 sec, Reload timer 0 mov TL0,#0B8H setb TR0 Start Timer 0 djnz multiplier,check_timer //Decrement multiplier by 1 & check if its 0 multiplier,#MULTIPLIER_DEFAULT ret end

// // / //0. //

mov

Bibliography:

http://www.lcdinterfacing.info/SevenSegment-Display.php http://www.encyclopedia.com http://www.8052.com/tutlcd

MULTIPLIER_DEFAULT DATA 20 //20 x 0.05 = 1 sec ORG 0000h mov multiplier,#MULTIPLIER_DEFAULT mov TMOD,#01h // Timer 0 Mode 1(16 bit mode) TH0,#3ch sec mov TL0,#0B8H TR0 Timer 0 loop: call //wait for 1 second setb led1 //TURN OFF LED call check_timer //wait for 1 second ajmp loop check_timer: led1 //TURN ON LED check_timer clr mov //0.05 setb //Start

Вам также может понравиться