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

Pythagorean triplet

question:

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^(2) + b^(2) = c^(2)
For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2).
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
answer:
#include
#include
void main()
{
 long int a,b,c,as,bs,cs;
 clrscr();
 for(a=1;a<1000;a++)
  for(b=1;b<1000;b++)
   for(c=1;c<1000;c++)
   {
    as=a*a;
    bs=b*b;
    cs=c*c;
    if((as+bs)==cs)
     {
     if(a+b+c==1000)
      printf("a=%ld,b=%ld,c=%ld\t as=%ld,bs=%ld,cs=%ld\tproduct=%ld\n",a,b,c,as,bs,cs,a*b*c);
     }
   }
 printf("over\n");

 getch();

answer:31875000

posted under , | 0 Comments

prime number

question:

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6^(th) prime is 13.
What is the 1001^(st) prime number?
answer:
  #include
#include
void main()
{
 long int i,j,prime,count=0;
 clrscr();
 for(i=2;i<10000;i++)
 {
  prime=1;
  for(j=2;j<=i/2;j++)
   {
    if(i%j==0)
     {
      prime=0;
     }
   }
   if(prime==1)
   {
    count=count+1;
    if(count==1001)
    {
    printf("%ld is prime\n",i);
    break;
    }
   }
  }
  printf("count is %ld",count);
  getch();
}
answer:7927

posted under , | 0 Comments

Differance between sum square and square sum

question:

The sum of the squares of the first ten natural numbers is,
1^(2) + 2^(2) + ... + 10^(2) = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^(2) = 55^(2) = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
answer:
#include
#include
void main()
{
 long int i,sum=0,sq=0;
 clrscr();
 for(i=0;i<=100;i++)
 {
  sum=sum+i;
  sq=sq+(i*i);
 }
 printf("sum sq=%ld,sq=%ld,diff=%ld",sum*sum,sq,(sum*sum)-sq);
 printf("over");
 getch();
}

output:25164150

posted under , | 0 Comments

palindromic number

hello friends,
recently i have started working on projecteular.net which tests our programming skill... so i have created few programs... those codes are here..one after other
question:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.

answer:
#include
#include
void main()
{
 long int d0,d3,d2,d1,d5,d4,i,j,l,max=0;;
 clrscr();
 for(l=999;l>100;l--)
 for(i=999;i>100;i--)
  {
   j=l*i;
// j=986689;
   d5=(j%10);
   d4=((j-d5)%100)/10;
   d3=((j-d5-d4)%1000)/100;
   d2=((j-d5-d4-d3)%10000)/1000;
   d1=((j-d5-d4-d3-d2)%100000)/10000;
   d0=((j-d5-d4-d3-d2-d1)%1000000)/100000;
   if(d0==d5)
    if(d1==d4)
     if(d2==d3)
      {
       printf("l=%ld,i=%ld,j=%ld\n",l,i,j);
       if(max
       max=j;
      }
  }
 printf("max is %ld",max);
 getch();
}

Answer:906609

posted under , | 0 Comments
Newer Posts Older Posts 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