8051

1.Keypad Interfacing using 8051 C programming:
Source code:
#include<reg51.h>
#define col P3
#define row P2
#define ldata P1
sbit rs=P0^0;
sbit rw=P0^1;
sbit en=P0^2;
sbit busy=P1^7;

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

void lcdready()
{
busy=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
en=1;
}
return;
}

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

void lcd()
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x80);
}

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


void main()
{
int k=0;
unsigned char b[]=" ENTER DIGITS";
unsigned char key[4][4]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
unsigned char cl,rl;
int z;
bkl:
lcd();
for(z=0;z<12;z++)
{
lcddata(b[z]);
}
lcdcmd(0xC0);
while(1)
{
   do
     {
      row=0x00;
      cl=col;
      cl&=0xFF;
      }while(cl!=0xFF);
    do
     {
      do
  {
   msdelay(20);
   cl=col;
   cl&=0xFF;
   }while(cl!=0xFF);
 msdelay(20);
 cl=col;
 cl&=0x0F;
 }while(cl==0xff);



while(1)
{
  row=0x0E;
  cl=col;
  cl&=0x0F;
   if(cl!=0x0F)
    {
     rl=0;
     break;
    }
  row=0x0D;
  cl=col;
  cl&=0x0F;
   if(cl!=0x0F)
    {
     rl=1;
     break;
    }
       row=0x0B;
  cl=col;
  cl&=0x0F;
   if(cl!=0x0F)
    {
     rl=2;
     break;
    }
       row=0x07;
  cl=col;
  cl&=0x0F;
   if(cl!=0x0F)
    {
     rl=3;
     break;
    }
   }
if(cl==0x0E)
lcddata(key[rl][0]);
else if(cl==0x0D)
lcddata(key[rl][1]);
else if(cl==0x0B)
lcddata(key[rl][2]);
else lcddata(key[rl][3]);
k++;
if(k%16==0)
goto bkl;
}
}




Keil and proteus files can be downloaded through this link










5 comments:

  1. i am beginner for embedded c.Can u help me to learn embeddedd c...where did i start to learn and how i develop a program?

    ReplyDelete
  2. Very significant Information for us, I have think the representation of this Information is actually superb one. This is my first visit to your site. Subjects in Automobile Engineering

    ReplyDelete
  3. Thank you for your articles that you have shared with us. Hopefully you can give the article a good benefit to us. Organic Hemp

    ReplyDelete