LCD INTERFACING


hi friends,
In Recent years,the LCD is finding widespread use replacing LEDs. everyone would like to have it in their project to attract the visitors. similarly we too had it in our project "Power On Coin", But we made a very small, tiny mistake while interfacing and we spend nearly a week to identify that problem. But, we learned many things about LCDs in that week, that's here
INTERFACING OF LCD
 All LCD will have minimum of 14 pins, some may have few more for back LED lights. knowledge of these 14 pins is enough to interface LCD. let we have a look at those 14 pins.

 









VSS:ground pin     VDD:+5v supply pin

VEE:contrast pin, by adjusting the supply to this pin we can get clarity in the display.
 NOTE: never give full 5V supply, vary it with a variable resistor(pot:10k)
RS: this register will say the LCD whether the information is command or data.
we would like to control the cursor in the display like clearing, moving the cursor in the display, entry mode, etc. this could be done through passing command by Rs=0->we can inform the LCD the information is command. respectively command words and codes are shown.
while we are passing data we should have Rs=1.
R/W:we are suppose to inform the LCD, whether the information is to be read or written on the LCD. this pin will do that work.
R/W=1->read mode
R/w=0->write mode
ENABLE PIN:very important pin of all, only when pass high to low signal to this pin, the command/data will be latched into LCD. But should have at least 450ns gap between setting and clearing this pin. because the micro controller may be working at MHz but our LCD will be working at KHz . so, we need to apply some delay else the date will not be proper.
E line is negative edge triggered- to write
E line is positive edge triggered- to read

D7-D0:information should be sent/received only through pin only this is data pin. ASCII key values of the corresponding character or command should be alone sent/received through this pin.
these are those 14 pins.
WORKING:
  • First we should configure the LCD,so we need to pass the command code. Don't send all, send only which are required.
Load D7-D0 with command code
Rs=0; to inform it is command
R/W=0; we are going to write it
E=1; to set E high
delay: to match the speed [450 ns]
E=0; low to latch the data
  • Then we can pass the information 
Load D7-D0 with data
Rs=0; to inform it is word
R/W=0/1; depends on us, whether we would like to read or write
E=1; to set E high-write/low-read
delay: to match the speed [450 ns]
E=0; low to latch the data/high to read

BUSY FLAG:
we are using delay, because the LCD need time to do some internal operation. but we cannot import exact delay, so it may slow down the process. so by using Busy flag we can over come this problem.
here, we use Rs=0 to check the busy flag bit to see if the LCD is ready to receive information. Thus busy flag is D7 and can be read when R/W=1 and Rs=0, as follows: if R/W=1, Rs=0. when D7 =1, the LCD is busy taking case of internal operations and will not accept any new information. when D7=0, the LCD is ready to receive new information.
It is better to use busy flag, rather than imparting delay everywhere use of Busy flag will make the program to run faster.
NOTE: one important thing here is, we need to send low to high signal to enable pin. since we are reading.
PROGRAM:
  • sending commands and data to LCDs with a time delay
;calls a time delay before sending next data/command
;p1.0-p1.7 are connected to LCD data pin D0-D7
;p2.0 is connected to Rs pin of LCd
;p2.1 is connected to R/W pin of LCD
;p2.2 is connected to E pin of LCD
    org 0000H
    mov a,#38H    ;init. LCD 2 lines, 5X7 matrix
    acall comwrt    ;call command subroutine
    acall delay    ;give LCD some time
    mov a,#0EH    ;display on,cursor on
    acall comnwrt    ;call command subroutine
    acall delay    ;give LCD some time
    mov a,#01    ;clear LCD
    acall comnwrt    ;call command subroutine
    acall delay     ;give LCD some time
    mov a,#06H    ;shift cursor right
    acall cmnwrt    ;call command subroutine
    acall delay    ;give LCD some time
    mov a,#'h'    ;display letter h
    acall datawrt    ;call display subroutine
    acall delay     ;give LCD sometime
    mov a,#'i'    ;display letter i
    acall datawrt     ;call display subroutine
again:    sjmp again    ;stay here

comnwrt:        ;send command to LCD
           mov p1,a    ;copy reg a to port1
           clr p2.0    ;Rs=0 for command
           clr p2.1    ;R/W=0 for write
          setb p2.2    ;E=1 for high pulse
          acall delay    ;give LCD some time
         clr p2.2    ;give LCD some time
         RET        ;return
   
datawrt:        ;write data to LCD
           mov p1,a    ;copy reg a to port1
           setb p2.0    ;Rs=1 for data
           clr p2.1    ;R/W=0 for write
           setb p2.2    ;E=1 for high pulse
           acall delay    ;give LCD some time
           clr p2.2    ;E=0 for high to low pulse
            ret        ;return

delay:    mov r3,#50    ;50 or higher for fast CPUs
here2:   mov r4,#255    ;r4=255
here:     Djnz r4,here    ;stay until r4 becomes 0
            Djnz r3,here2    ;stay until r3 becomes 0
            return        ;return
             end

  • sending commands and data to LCDs using busy flag  
 ;check busy flag before sending data,command to LCD
;p1=data pin, p2.0=Rs,p2.1=R/W,p2.2=E pins
    mov a,#38H    ;init LCD 2 lines,5x7 matrix
    acall command     ;issue command
    mov a,#0EH    ;LCd on, cursor on
    acall command    ;issue command
    mov a,#01H    ;clear LCD command
    acall command    ;issue command
    mov a,#06H    ;shift cursor right
    acall command    ;issue command
    mov a,#86H    ;cursor: line 1,pos 6
    acall command    ;issue command
    mov a,#'h'    ;display letter h
    acall data_dispaly     ;issue data
    mov a,#'i'    ;diaplay letter i
    acall data_display    ;issue data
here:    sjmp here    ;stay here

command:
    acall ready     ;is LCD ready?
    mov p1,a    ;issue command code
    clr p2.0    ;Rs=0 for command
    clr p2.1    ;R/W=0 for write
    setb p2.2    ;E=1 for high pulse
    clr p2.2    ;give LCD some time
    RET        ;return

data_display:
    acall ready    ;is LCD ready?
    mov p1,a    ;copy reg a to port1
    setb p2.0    ;Rs=1 for data
    clr p2.1    ;R/W=0 for write
    setb p2.2    ;E=1 for high pulse
    clr p2.2    ;E=0 for high to low pulse
    ret        ;return  

ready:
    setb p1.7    ;make p1.7 input port
    clr p2.0    ;Rs=0 access command reg
    setb p2.1    ;R/w=1 read command reg
;read command reg and check busy flag
back:    clr p2.2    ;E=0 for low to high pulse
    setb p2.2    ;E=1 low to high pulse
    jb p1.7,back    ;stay until busy flag=0
    ret        ;return
  
    end

i said that we made a very small mistake and we were spending a week in it. the mistake is that,we gave +5V
to VEE pin, we need to vary it as we vary contrast in TV. But, we thought we made mistake in the program and we were checking the program for 5 days
so, always view the problem in various angle, that will give solution quickly...

5 comments:

rohith said...

Thanks a lot.

rohith said...

Thanks a lot...

rohith said...

Thanks a lot.

ALAGAPPAN said...

you are very much welcome rohith...

Anonymous said...

Nice article.

Also found one more good article:
http://electrofriends.com/articles/electronics/microcontroller-electronics-articles/8051-8951/interfacing-an-lcd-to-the-8951-microcontroller/

Newer Post Older Post Home

About Me

My photo
Hi everyone,myself Alagappan...electronic and communication engg. student... living in madurai... interested in everything... want to achieve something great in my lifetime...

Followers


Recent Comments