LCD Excersise 8051

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

This is special section of web-site. In this section we will learn how we can display a character or a message on LCD display.

You can choose any standard LCD available in market. I have experimented with 202 LCD. It means LCD has 2 lines of 20 characters each. Many other LCDs like 162, 242, 322, 204 etc. are available. Functionally all these LCDs are same. To develop a protocol to interface this LCD with 89C51 first we have to understand how they functions. These displays contains two internal byte-wide registers, one for command and second for characters to be displayed. There are three control signals called R/W, DI/RS and En. The table given below will tell you what is the use of these three signals. Control Signals R/W RS/DI En It's function = 0 Writes character in display = 1 Reads from display = 0 Selects command register = 1 Selects Data register to display character = 0 Disables the display = 1 Enables the display

By making RS/DI signal 0 you can send different commands to display. These commands are used to initialized LCD, to select display pattern, to shift cursor or screen etc. The different commands and their functions are as given below Bits Function RS/DI R/W D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0 0 0 0 1 Clear LCD memory, Home cursor 0 0 0 0 0 0 0 0 1 0 Clear and Home cursor only s = 1/0 : Shift screen/cursor, I/O = 0 0 0 0 0 0 0 1 I/O s 1/0 : shift R/L D = 1/0 : Screen On/Off. C = 1/0 : 0 0 0 0 0 0 1 D C B cursor On/Off. B = 1/0 : Cursor blink/no blink S/C = 1/0 : Screen / Cursor. R/L = 0 0 0 0 0 1 S/C R/L 0 0 1/0 : Shift one space right / left D/L = 1/0 : 8/4 bits per character. N = 0 0 0 0 1 DL N F 0 0 1/0 : 2/1 rows of char. F = 1/0 : 510/57 dots/char. 0 0 0 1 Char address Write to char. RAM address after this Writes to display RAM address after 0 0 1 Display data address this

1 1

1 0 1

BF

Current address Character type Character type

BF = 1/0 : display is busy/not busy Write byte to last RAM chosen Read byte from last RAM chosen

The figure shows connections of LCD with 89C51

All the data lines of LCD are connected with port P1. En pin is connected with P0.0, DI (RS) is connected with P0.1 and R/W pin is connected with P0.2. Next the program is given in 8051 assembly language with necessary comments that can display a message or single character on screen. com equ 0fch header dat equ 0fdh eof equ 0feh org 00h mov dptr,#2000h acall msg mov a,#c0h acall cmmd mov a,#'L' acall dis mov a,#'C' acall dis mov a,#'D' ; Initilize LCD and display message ; "Wel - Come To ; Go to the next line ; and display character 'L' ; and display character 'C' ; and display character 'D' ; command follows this ; Data follows this header ; End of message

acall dis mov dptr,#3000h acall msg here: sjmp here msg: acall ready clr a movc a,@a+dptr inc dptr cjne a,#eof,cmd ret cmd:cjne a,#com,data clr p0.1 sjmp msg data:cjne a,#dat,send setb p0.1 sjmp msg send: mov p1,a clr p0.2 setb p0.0 clr p0.0 sjmp msg cmmd: acall ready mov p1,a clr p0.1 register clr p0.2 setb p0.0 clr p0.0 ret dis: acall ready mov p1,a setb p0.1 clr p0.2 setb p3.7 clr p3.7 ret ready: mov r7,p0 clr p0.0 clr p0.1 setb p0.2 wait:clr p0.0

; display word 'program' in next line ; after character 'D'. ; continue loop ; wait until display is busy ; get the character ; point to next character ; if end of message then ; return from sub routine ; if command then DI (RS) = 0 ; go until done ; if data then DI (RS) = 1 ; go until done ; send data/command to display ; write enable ; strobe character to display ; go until done

; wait until display is busy ; command chara. in p1 ; select com. ; write enable ; strobe the chara.

; wait until display is busy ; data chara. in p1 ; select data register ; write enable ; strobe the chara.

; save content of P0 ; disable display ; select command register ; read enable ; strobe display

setb p0.0 jb p1.7,wait clr p3.7 mov p0,r7 ret org 2000h db com db 3ch db 0fh db 01h db dat db 'Wel-Come To' db eof org 3000h db com db 0c5h db dat db 'Program' db eof end

; read busy status of display ; wait for busy ; restore content of P0 ; messages are stored at ; locations 2000h and 3000h

You might also like