lcd interfacing with 8051

this article make you learn how to interface LCD(Liquid Crystal Display) with 8051 micro-controller. LCD has wide advantages in real world application. it is an important output device to keep track all automated and semi-automated devices. in all LCDs we are using 16*2 which is very common module generally used by a novice .

PROTEUS DESIGN

in this design 8 bit data line of parallel communication is used to transfer data on LCD which  is to be printed on screen. rs,rw,en of LCD is connected to I/O pin of your choice.

CODE:

for printing any message on LCD three steps must be followed as

1.LCD initializing

2.send commands to LCD

3. send a character

function lcdint() is being used to select mode of operation(4bit or 8bit),fix cursor position and set other properties of LCD. to make it sure for LCD that the data so transfer to it is  either command or not.if it's command we have to select rs=0,the instruction command code register is selected.

similarly in third and last step for the character you want to print on LCD you have to make rs=1,the instruction data code register is selected allowing user to send data to be displayed on LCD.

complete code

#include<reg51.h>
#define lcdport P2
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^2;
void lcdcmd(char);
void lcdint();
void lcddata(char);
void lcdstring(char *);
void delay(unsigned int);

void main()
{
lcdport=0x00;               // output port
 while(1)
  {
   lcdint();
   delay(500);
   lcdstring("hello welcome to");
   lcdcmd(0xc0);
   delay(500000);
   lcdstring("projectguru.net");
   delay(500000);
   }
}         
void delay(unsigned int x)
{
 unsigned int i;
 for(i=0;i<x;i++);
}
void lcdint()               // lcd initializing
{
  lcdcmd(0x38);
  delay(500);
  lcdcmd(0x01);
  delay(500);
  lcdcmd(0x0c);
  delay(500);
  lcdcmd(0x80);
  delay(500);
  lcdcmd(0x0e);
  delay(500);
}
void lcdcmd(char value)        //  lcd command
{
  lcdport = value;
  rw=0;
  rs=0;
  en=1;
  delay(500);
  en=0;
}
void lcdstring(char *p)      
{
  while(*p!='\0')
   {
     lcddata(*p);
     delay(2000);
     p++;
   }
}
void lcddata(char value)   // print data on lcd
{
  lcdport = value;
  rs=1;
  rw=0;
  en=1; 
  delay(500);
  en=0;
}

VIDEO


Category: 

tags: 

Share

Who's new

  • ravirajpatil871...
  • shubhambajoria
  • yassir
  • demiholyman890954
  • scottgillum51169040

Get Notified

 

Share

We are Social

Syndicate

Subscribe to Syndicate