LCD interfacing to 8051



In recent years LCD is finding widespread use replacing LEDs

 1. The declining prices of LCD
 2.The ability to display numbers, characters,   and graphics
 3.Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of
    the task of refreshing the LCD
 4.Ease of programming for characters and Graphics







                                                                                                                         
                                 

    LCD pin description

The  LCD has 16 pins . The function of each pin is given below:
Vcc, Vss and Vee
While Vcc and Vss provides +5v and ground ,respectively, Vee is used to control the contrast of LCD.
RS(register select)
There are two very important registers inside the LCD. The RS pin is used to select them.If RS =0, the instruction command code register is selected allowing the user to send a command such as clear display etc. If RS=1 , data register is selected ,allowing the user to display data on LCD.
R/W(read/write)
This pin is used to select the read and write operation of LCD.
E(enable)
This pin is used to latch the data into the LCD presented on data pins. A high to low pulse must be applied to latch the data.
D0-D7
These are the data pins of LCD,used to send the data and command to LCD.
Led+,Led-
These two pins are used to provide +5v and ground to the backlight LED.

                        



                                 Pin                                    Description
                        
                                   1.                                      Ground
                                   2.                                    +5v power supply
                                   3.                                      Supply to control contrast
                                   4.                                      To select register(RS)
                                   5.                                      To select read or write          
                                                                            operation(R/W)
                                   6.                                      enable pin(E)
                                   7-14.                                8 bit data bus
                                   15.                                    Led+
                                   16.                                    Led-



                                                





   Commands for LCD

           Code(hex)                     Command to LCD instruction register
                1                                                   Clear display screen
                2                                                   Return home
                4                                                   Shift cursor to left
                6                                                   Shift cursor to right
                5                                                   Shift display right 
                7                                                   Shift display left
                8                                                   Display off, cursor off
                A                                                  Display off , cursor on
                C                                                  Display on, cursor off
                E                                                  Display on, cursor blinking
                F                                                  Display on ,cursor blinking
               10                                                 Shift cursor position to left
               14                                                 Shift cursor position to right
               18                                                 Shift the entire display to left
               1C                                                Shift the entire display to right
               80                                             Force cursor to beginning of 1s line
               C0                                            Force cursor to beginning of 2line
               38                                                 2 lines and 5x7 matrix


PROGRAM TO DISPLAY CHARACTERS ON LCD

P1 is connected to data pins of LCD
P3.1 is connected to RS pin of LCD
P3.2 is connected to R/W pin of LCD
P3.0 is connected to E pin of LCD


#include <reg51.h>
void MSDelay(unsigned int );
void lcdcmd(unsigned char);
void lcddata(unsigned char);
sbit rs = P3^1;
sbit rw = P3^2;
sbit en = P3^0;
void main()
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x86);
lcddata(‘M’);
lcddata(‘S’);
lcddata(‘K’);
}
void lcdcmd(unsigned char value)
{
P1 = value;
rs = 0;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
}

void lcddata(unsigned char value)
{
P1 = value;
rs = 1;
rw = 0;
en = 1;
MSDelay(1);
en = 0;
}

void MSDelay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}


         PROGRAM TO DISPLAY STRING ON LCD 


#include<reg51.h>
void delay(unsigned int );
void lcdcmd(unsigned char);
void lcddata(unsigned char);
sbit rs = P3^1;
sbit rw = P3^2;
sbit en = P3^0;
void main ()

{
 unsigned char str[]="MANPREET SINGH AKALI";
 unsigned char i=0;
          P2=0x00;
          P1=0x00;
          P3=0x00;
         
          while(1)
          { 
          lcdcmd(0x38);
          delay(50);
          lcdcmd(0x0E);
          delay(50);
  lcdcmd(0x01);
  delay(50);
  lcdcmd(0x80);
  delay(50);

          while (str[i]!='\0'){
                   lcddata(str[i]);
                   if(i==15) {
                             lcdcmd(0x0C0);
              delay(50);
                   }
                   delay(1500);
                   i++;
                   }
          delay(5000);
                  
         
}
}


          void lcdcmd(unsigned char value)
{
          P1= value;
          rs = 0;
            rw = 0;
            en = 1;
            delay(1);
            en = 0;
         
          return;
}

void lcddata(unsigned char value)
{
                   P1=value;
          rs=1;
          rw=0;
          en=1;
          delay(1);
          en=0;
}


void delay(unsigned int time)
{
          unsigned int i,j;
          for(i=0;i<time;i++)
          for(j=0;j<50;j++);
}



Comments

Popular Posts