Maker Pro
Maker Pro

3x4 keypad and lcd interfacing with 8051

hi, i want to interface 3x4 keypad and 16x2 lcd with 8051. i want to get input from keypad and then take decisions accordingly, please give keil uvision3 based code and proteus 6.9 based circuit simulation

1) it will show "toll plaza"
and wait for 2 seconds approx
2) it will ask "1 for two wheeler "
"2 for four wheeler"
3)on pressing 1 or 2 it will ask "enter your i.d"
4) if entered i.d matches with the saved i.d then it will show "you paid $5/$3" depending on vehicle size.
5) after that it should say "thanks"
"your balance is xxxx"
 
Hi, I want $1,000,000. Please give me your email and I will send instructions on where to send it.

Bob
 
So what is this for and what do you have done so far?

The specifics sure lend towards a school project, can't see why else the details on what to use would be so specific and yet the project so generic...
 
if it isn't for homework then its for business. if its for business then you should pay for help provided.... well thats my thought.
 
So what is this for and what do you have done so far?

The specifics sure lend towards a school project, can't see why else the details on what to use would be so specific and yet the project so generic...

this was a semester project of my junior it attracted me,, i have written a separate code for lcd which is working well,, now i am working on keypad code and after this i will integrate both code to make a single unit,,, i have written a code in c on keil uvision3 and simulated usng proteus 6.9,, its not working well ,, here is the code,,

Code:
#include<reg51.h>

unsigned char x=3,y=5,z=6,key=0,col,b=0,a=0x07;
//void key_release(void);
void read(void);
void MSDelay(unsigned int);
void pol(void);
void polrow1(void);
void polrow2(void);
void polrow3(void);
void polrow4(void);
void polcol(void);
void polco2(void);
void polco3(void);
void polco4(void);
void main()
{
P0=0XFF;
P1=0;
P3=0;
//key_release();
pole();
read();
}


void polcol1()
{
if(b=z)
P1=0x49;
else if(b=y)
P1=0x50;
else if(b=x)
P1=0x51;
else 
polrow2();
}

void polcol2()
{
if(b=z)
P1=0x52;
else if(b=y)
P1=0x53;
else if(b=x)
P1=0x54;
else 
polrow3();
}
void polcol3()
{
if(b=z)
P1=0x55;
else if(b=y)
P1=0x56;
else if(b=x)
P1=0x57;
else 
polrow4();
}
void polcol4()
{
if(b=z)
key='*';
else if(b=y)
P1=0x48;
else if(b=x)
key='#';
else 
pol();
}

void polrow1()
{
P3=254;
b=P0;
b=b&&a;
if(b!=a)
polcol1();
}
void polrow2()
{
P3=0xfd;
b=P0;
b=b&&a;
if(b!=a)
polcol2();
}
void polrow3()
{
P3=0xfb;
b=P0;
b=b&&a;
if(b!=a)
polcol3();
}
void polrow4()
{
P3=0xf7;
b=P0;
b=b&&a;
if(b!=a)
polcol4();
}


//void read()
//{
//b=b&&a;
//if(b!=a)
//polrow1();
//else
//pol();
//return;
//}


void pol()
{
MSDelay(20);
col=P0;
b=col&&a;
if(b!=a)
polrow1();
else
pole();
return;
}


//void key_release()
//{
//col=P0;
//b=col&&a;
//if(b!=a)
//pol();
//else
//pol();
//return;
//}

void MSDelay(unsigned int itime)
{
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
 
Perhaps you can explain in words (or comment your code).

i have made a new code,, in this code a problem is occuring,, i am unable to set the loops so that the display on lcd is permanent.. display is removed after a delay of msdelay(10),, i have used this function so that i can see output for some time otherwise there is no use of msdelay(10)

please correct this code so that display is permanent untill i press the next key, please
there is another problem in this code,,, any key from first coloumn i.e '1' , '4' , '7' , '*' is detected only ince if i keep one of these keys pressed, to show it again it needs to be pressed again.. while keys of other coloumns are being detected and displayed well
Code:
#include <reg51.h>
char code column[] = {0xbf,0xdf,0xef};
//char code name[] = {0x69,0x6d,0x72,0x61,0x6e};
unsigned char out;
void msdelay(unsigned int);
void keypad(void);
void lcddata(unsigned char);
void lcdcmd(unsigned char);
sbit rs = P2^0;
sbit rw = P2^1;
sbit en = P2^2;
//unsigned char h;
void main (void)
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
P1=0xf0;
P3=0;
keypad();
//for(h=0;h<4;h++)
//{
//lcddata(name[h]);

//}
}

void keypad ()
{

unsigned char x,key;
if(P1!=0xf0)
     {
       for (x=0; x<3; x++)
             {							   
              P1=column[x];
              
              							   
                       key=P1;
switch(key)
{
case 0xb7 : lcddata('1');break;
case 0xd7 : lcddata('2');break;
case 0xe7 : lcddata('3');break;
case 0xbb : lcddata('4');break;
case 0xdb : lcddata('5');break;
case 0xeb : lcddata('6');break;
case 0xbd : lcddata('7');break;
case 0xdd : lcddata('8');break;
case 0xed : lcddata('9');break;
case 0xbe : lcddata('*');break;
case 0xde : lcddata('0');break;
case 0xee : lcddata('#');break;
}
                    
             }
     }


}

void lcddata(unsigned char datta){
P3 = datta; //put the value on the pins
rs = 1;
rw = 0;
en = 1; //strobe the enable pin
msdelay(1);
en = 0;
msdelay(10);
return;
}

void lcdcmd(unsigned char value){
//lcdready(); //check the LCD busy flag
P3 = value; //put the value on the pins
rs = 0;
rw = 0;
en = 1; //strobe the enable pin
msdelay(2);
en = 0;
return;
}

void msdelay(unsigned int itime){
unsigned int i, j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
 
Last edited:
Top