Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

keypad interfacing with 8051

Status
Not open for further replies.

svinoth86

Newbie level 6
Joined
Nov 13, 2010
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,420
how interface keypad with 8051........?

---------- Post added at 12:59 ---------- Previous post was at 12:56 ----------

//P2=keypad connected
//P1=lcd connected
#include <REGX51.H>
#include"lcd.c"
sbit r1=P2^0;
sbit r2=P2^1;
sbit r3=P2^2;
sbit r4=P2^3;
sbit c1=P2^4;
sbit c2=P2^5;
sbit c3=P2^6;
sbit c4=P2^7;
sbit rs=P3^5;
sbit rw=P3^6;
sbit en=P3^7;
delay(unsigned int i)
{
while(i--);
}
lcd_cmd(unsigned char c)
{
P1=c;
rs=0;
rw=0;
en=1;
delay(150);
en=0;
}
lcd_data(unsigned char c)
{
P1=c;
rs=1;
rw=0;
en=1;
delay(150);
en=0;
}
lcd_init()
{
lcd_cmd(0x38);
lcd_cmd(0x0c);
lcd_cmd(0x01);
lcd_cmd(0x80);

}
void main()
{
lcd_init();
lcd_data('a');
while(1)
{

P2=0xf0; //column=1111 rows=0000
while(P2==0xf0);

P2=0xfe;//c=1111 r=1110
if(!r1)
{

if(!c1)
{
lcd_data('1');while(!c1);
}
if(!c2)
{
lcd_data('2');while(!c2);
}
if(!c3)
{
lcd_data('3');while(!c3);
}
if(!c4)
{
lcd_data('4');while(!c4);
}
}

P2=0xfd;//c=1111 r=1101
if(!r2)
{

if(!c1)
{
lcd_data('5');while(!c1);
}
if(!c2)
{
lcd_data('6');while(!c2);
}
if(!c3)
{
lcd_data('7');while(!c3);
}
if(!c4)
{
lcd_data('8');while(!c4);
}
}

P2=0xfb;//c=1111 r=1011
if(!r3)
{
if(!c1)
{
lcd_data('9');while(!c1);
}
if(!c2)
{
lcd_data('a');while(!c2);
}
if(!c3)
{
lcd_data('b');while(!c3);
}
if(!c4)
{
lcd_data('c');while(!c4);
}
}

P2=0xf7;//c=1111 r=0111
if(!r4)
{
if(!c1)
{
lcd_data('d');while(!c1);
}
if(!c2)
{
lcd_data('e');while(!c2);
}
if(!c3)
{
lcd_data('f');while(!c3);
}
if(!c4)
{
lcd_data('0');while(!c4);
}
}
}
}
 

What information you need exactly? I can see that, you just checked IO status to display a character on LCD. But you may see lot many characters on display for a single key press.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top