Saturday, August 17, 2013

lcd interface

COMPLETE INTERFACING LCD WITH MICRO-CONTROLLER USING C-PROGRAMMING


STEPS 

1. What is LCD? Which LCD are we going to use ? What is the LCD address bit ? 
   -  Here I'm going to use is the 16*2 LCD .total of 16 pins. It has 8 bit data address(can also be used for 4 bit addressing ) i.e it can carry out the 8 bit data for displaying . 3 pins for power supply , ground and contrast . 3 pin for control register , read write and enable pin and remaining 2 pin for background light .

   PIN DIAGRAM WITH FIGURE 









                           Fig(a) : Connection of Microcontroller(8051 family) with LCD 

  
Table 1: Complete LCD pin and its functions


Table 2: LCD command set instruction




2. CONNECT THE LCD WITH THE MICRO-CONTROLLER AS FIGURE BELOW  :
  - NOTE :- you can connect the data and control lines in any input / output port directly . But for
 port-0 of 8051 family you have to connect with LCD only after connecting it with resistor of 8Kohm as in figure below:- 

  Figure : Pull-up resistors connection with atmel 8051 family microcontroller


3: If you are not using the port-0 for the data lines , then you can connect  the pins of lcd to port 1,port2 and port3 because they donot need any pull-up resistors. For the figure below ,i have used port-2 as data lines. Here i have not given power supply to microcontroller and lcd because the proteus by default give the power supply and ground to each pin of lcd and microcontroller.


Fig: Proteus design sample for LCD interfacing


4. After all , we need the program to be load in microcontroller in order to interface with LCD. So for this , the microcontroller need the machine level code. And for this we have to convert the program in hex(.hex) file . i.e It represents al the code into the hexadecimal format which is understand by the microcontroller. For this i have the following code wriiten in Keil software which generate the hex file.
you can download the keil or mide software .

5. The code is given below :

               #include<reg51.h>
                         #define data P2 //initialize port 2 as data lines
sbit rs=P3^7;    // initialize port for rs
sbit rw=P3^6;    //initialize port for rw
sbit e=P3^5;     //initialize port for e 
void delay(int x)   // delay function 
    {  
int i,j;
       for(i=0;i<1275;i++)
 for(j=0;j<x;j++);
 }
void lcdcmd(unsigned char value)  // lcd command function
          {
rs=0;
  rw=0;
  P2=value;
  e=1;
  delay(25);
  e=0;
}  
 void lcddata(unsigned char value)  // lacd data function to write in lcd
 {
 rs=1;
 rw=0;
  P2=value;
 e=1;
 delay(2);
 e=0;
 }
 void initlcd()
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
}

 void main()
 {
 int i;
 int j;
 char arr[]="my name is hari chalise";  //  which is to be written in lcd , simply change                                                                                  //  of your own wish 
  initlcd();
 for(i=0;i<=(sizeof(arr)-1);i++)
 { 
 lcddata(arr[i]);
 delay(3);
 if(i>=14) // to check if length of arr is greater than 14 then shift the display in left by 1 character so 
{    // all the character are displayed how much the character is long
lcdcmd(0x07);
       }
 }
  lcdcmd(0xC0);
                         while(1)
                {
          lcdcmd(0x18);
         delay(2);
                         } 
 }
  
6. At last the hex code format of above code is :

:100975006D79206E616D65206973206861726920EB
:080985006368616C6973650091
:10094F00E4FDFCE4FBFAC3EB9FEE6480F8EA6480FD
:10095F009850070BBB00010A80EC0DBD00010CBCC9
:05096F0004E1BDFBDE08
:010974002260
:10098D00C2B7C2B68FA0D2B57F197E0012094FC271
:02099D00B52281
:10099F00D2B7C2B68FA0D2B57F027E0012094FC266
:0209AF00B5226F
:0F09B1007F3812098D7F0E12098D7F0102098D8B
:1008F600780A7C007D007BFF7A0979757E007F1877
:100906001208D01209B1900000AF82740A2FF8E6DF
:10091600FF12099F7F037E0012094FC3E582940EE2
:10092600E5836480948040057F0712098DA3E582E4
:100936006418458370D37FC012098D7F1812098D04
:090946007F027E0012094F80F2CD
:030000000209C032
:0C09C000787FE4F6D8FD7581210208F66E
:10080000E709F608DFFA8046E709F208DFFA803EDA
:1008100088828C83E709F0A3DFFA8032E309F608C7
:10082000DFFA8078E309F208DFFA807088828C832F
:10083000E309F0A3DFFA806489828A83E0A3F608E3
:10084000DFFA805889828A83E0A3F208DFFA804CBD
:1008500080D280FA80C680D4806980F28033801094
:1008600080A680EA809A80A880DA80E280CA8033FD
:1008700089828A83ECFAE493A3C8C582C8CCC58375
:10088000CCF0A3C8C582C8CCC583CCDFE9DEE78045
:100890000D89828A83E493A3F608DFF9ECFAA9F0C4
:1008A000EDFB2289828A83ECFAE0A3C8C582C8CC1A
:1008B000C583CCF0A3C8C582C8CCC583CCDFEADE33
:1008C000E880DB89828A83E493A3F208DFF980CC95
:1008D00088F0EF60010E4E60C388F0ED2402B4048E
:1008E0000050B9F582EB2402B4040050AF23234535
:0608F00082239008507302
:00000001FF


save this code in notepad as (.hex) file name and run through proteus .


If you find difficulty  and if there are any mistake , comment are highly acknowledged. Thank you  

1 comment:

  1. do you see that table of lcd commands.....there is one missing....its delete signle character....if you know it plz tell me in binnary or decimal instruction code

    ReplyDelete