#include<reg52.h>
#define COL P2
#define ROW P1
unsigned char keypad[4][4]={'0','1','2','3',
'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};
void msdelay(unsigned int);
void sertx(unsigned char);
void main()
{
unsigned char colloc,rowloc;
TMOD=0x20;
SCON=0x50;
TH1=0xFD;
TR1=1;
COL=0xFF;
while(1)
{
do
{
ROW=0x00;
colloc=COL;
colloc&=0x0F;
}while(colloc!=0x0F);
do
{
do
{
msdelay(20);
colloc=COL;
colloc&=0x0F;
}while(colloc==0x0F);
msdelay(20);
colloc=COL;
colloc&=0x0F;
}while(colloc==0x0F);
while(1)
{
ROW=0xFE;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=0;
break;
}
ROW=0xFD;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=1;
break;
}
ROW=0xFB;
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=2;
break;
}
ROW=0xF7;
colloc=COL;
colloc&=0x0F;
rowloc=3;
break;
}
if(colloc==0x0E)
sertx(keypad[rowloc][0]);
else if(colloc==0x0D)
sertx(keypad[rowloc][1]);
else if(colloc==0x0B)
sertx(keypad[rowloc][2]);
else
sertx(keypad[rowloc][0]);
}
}
void sertx(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
}
void msdelay(unsigned int time)
{
unsigned char i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
this is code.i hav tried in proteus but not get o/p.how to make keypad in proteus