Tuesday, 3 November 2015

AT89C51 8BIT LCD INTERFACE (ARRAY METHOD)





 #include<reg51.h>
 sbit RS=P0^0;
 sbit RW=P0^1;
 sbit EN=P0^2;
 #define ldata P1
 void lcd_init();
 void cmd(unsigned char c);
 void dat(unsigned char c);
 void delay(unsigned int i);
 void main()
 {
 int p;
 char arr[12]={'E','M','B','E','D','D','E','D',' ','L','A','B'};
  lcd_init();
 for(p=0;p<12;p++)
 dat(arr[p]);
 while(1);

 }

 void lcd_init()
 {
 cmd(0X01);
 delay(10);
 cmd(0X08);
 delay(10);
 cmd(0X0e);
 delay(10);
 cmd(0X38);
 delay(10);
 }
 void cmd(unsigned char c)
 {
  int i;
  ldata=c;
  RS=0;
  RW=0;
  EN=1;
  for(i=0;i<10;i++);
  EN=0;
  return;
 }
 void dat(unsigned char c)
 {
 int i;
 ldata=c;
 RS=1;
 RW=0;
 EN=1;
 for(i=0;i<=10;i++);
 EN=0;
 return;
 }
 void delay(unsigned int b)
 {
 unsigned int i,j;
 for(i=0;i<b;i++)
 for(j=0;j<3000;j++);
 }

AT89C51 LCD(4BIT) INTERFACE





#include<reg51.h>
void cmd(unsigned char c);
void dat(unsigned char c);
void init();

void delay(unsigned int i)
{
while(i--);
}
void string(unsigned char *);
void main()
{
init();
cmd (0x80);
string("EMBEDDED LAB");
cmd (0xc0);
string("WWW.SUMMITBHARDWAJ.BLOGSPOT.IN");
while(1)
{
}
}
void init()
{
cmd(0x02);
delay(1000);
cmd(0x28);
delay(1000);
cmd(0x01);
delay(1000);
cmd(0x0e);
delay(1000);

}
void cmd(unsigned char c)
{
unsigned char l,h;
l=(c&0x0f);
h=(c>>4);
P3=h;
P2=0x04;
delay(1000);
P2=0x00;
P3=l;
P2=0x04;
delay(1000);
P2=0x00;
}
void dat(unsigned char c)
{
unsigned char l,h;
l=c&0x0f;
h=c>>4;
P3=h;
P2=0x05;
delay(1000);
P2=0x01;
P3=l;
P2=0x05;
delay(1000);
P2=0x01;
}
void string(unsigned char *p)
{
while(*p!='\0')
{
delay(100);
 dat(*p);
 p++;
 }

 }

AT89C51 KEYPAD VALUE ON LCD




#include<reg51.h>
#define port P3
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
void delay()
{
unsigned int i;
for(i=0;i<3000;i++);
}
void cmd(unsigned int c)
{
port=c;
rs=0;
rw=0;
e=1;
delay();
e=0;
}
void dat(unsigned int c)
{
port=c;
rs=1;
rw=0 ;
e=1  ;
delay();
e=0;
}
void lcd_init()
{
cmd(0x01);
cmd(0x80);
cmd(0x0c);
cmd(0x38);
}
 void digit(unsigned int i)
 {
  unsigned char a,k=0x82;
   cmd(0x01);
  do
  {
  cmd(k--);
  a=i%10;
  dat(48+a);
  cmd(0x80);
  delay();
  i=i/10;
 }
 while(i>0);
 }
void main()
{
int a,b,c;
lcd_init();
P2=0x00;
while(1)
{
P1=0xf0;
while(P1==0xf0);
a=P1;
P1=0x0f;
b=P1;
while(P1!=0x0f);
c=a|b;
P2=c;
if(c==0xe7)
{
digit(1);
}
else if(c==0xeb)
{
digit(2);
}
else if(c==0xed)
{
digit(3);

}
else if(c==0xee)
{
digit(4);

}
else if(c==0xd7)
{
digit(5);
}
else if(c==0xdb)
{
digit(6);
}
else if(c==0xdd)
{
digit(7);
}
else if(c==0xde)
{
digit(8);
}
else if(c==0xb7)
{
digit(9);
}
else if(c==0xbb)
{
digit(10);
}
else if(c==0xbd)
{
digit(11);
}
else if(c==0xbe)
{
digit(12);
}
else if(c==0x77)
{
digit(13);
}
else if(c==0x7b)
{
digit(14);
}
else if(c==0x7d)
{
digit(15);
}
else if(c==0x7e)
{
digit(16);
}
}
}





AT89C51 KEYPAD VALUE ON LED BAR



#include<reg51.h>
void delay(unsigned int i)
{
while(i--);
}
void main()
{
int a,b,c;
P2=0x00;
while(1)
{
P1=0xf0;
while(P1==0xf0);
a=P1;
P1=0x0f;
b=P1;
c=a|b;
P2=c;
}
}