gauravkothari23
Advanced Member level 2
Hi all..
I am trying to interface keypad and Seven Segment display with 89S52.
what i need to do is whatever keys are pressed from keypad, it should show on seven segment display. for Eg. if 2 is pressed from keypad then display should show 2. and so on.
my code is...
i have not tried anything because i am not getting any idea of how to start with...
because the output from keypad i get is numbers. and to display on seven segment we need hex.
how can i do this.
in my code, in MAIN function i have just tried to save the numbers from what i get from keypad to array numbers[7].
seven segment display are common anode and are connected to port 1 of 89S52.
I am trying to interface keypad and Seven Segment display with 89S52.
what i need to do is whatever keys are pressed from keypad, it should show on seven segment display. for Eg. if 2 is pressed from keypad then display should show 2. and so on.
my code is...
Code:
#include<reg51.h>
#include<stdio.h>
sbit row0=P2^7; //assigning PORT-0 to read rows
sbit row1=P2^6; //assigning PORT-0 to read rows
sbit row2=P2^5; //assigning PORT-0 to read rows
sbit row3=P2^4; //assigning PORT-0 to read rows
sfr COL=0xA0; //assigning PORT-2 to read colomns
sbit buz=P3^2;
sbit seg0=P3^0;
sbit seg1=P3^1;
sbit seg2=P3^2;
sbit seg3=P3^3;
sbit seg4=P3^4;
sbit seg5=P3^5;
void msdelay(unsigned int value);
int keypad();
char digi[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};
unsigned char numbers[6]={"44444"};
void main()
{
unsigned int i;
while(1)
{
do
{
numbers[i]=keypad();
i++;
}
while(i!=6);
i=0;
{
P1=0x40;
}
}
} // MAIN ENDS HERE.
void msdelay(unsigned int value)
{
unsigned int i,j;
for(i=0;i<value;i++)
for(j=0;j<100;j++);
}
int keypad()
{
unsigned char dat[4][4]={'7','8','9','A', // assigning key matrix
'4','5','6','B',
'1','2','3','-',
'*','0','#','+',};
unsigned char colloc,rowloc;
COL=0x0F;
row0=0;
row1=0;
row2=0;
row3=0;
while(1)
{
do
{
do
{
msdelay(90);
colloc=COL;
colloc&=0x0F;
}
while(colloc==0x0F);
msdelay(90);
colloc=COL;
colloc&=0x0F;
}
while(colloc==0x0F);
while(1)
{
row0=0;
row1=1;
row2=1;
row3=1;
msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=0;
break;
}
row0=1;
row1=0;
row2=1;
row3=1;
msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=1;
break;
}
row0=1;
row1=1;
row2=0;
row3=1;
msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=2;
break;
}
row0=1;
row1=1;
row2=1;
row3=0;
msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=3;
break;
}
}
if(colloc==0x0E)
return(dat[rowloc][0]);
else if(colloc==0x0D)
return(dat[rowloc][1]);
else if(colloc==0x0B)
return(dat[rowloc][2]);
else
return(dat[rowloc][3]);
}
}
because the output from keypad i get is numbers. and to display on seven segment we need hex.
how can i do this.
in my code, in MAIN function i have just tried to save the numbers from what i get from keypad to array numbers[7].
seven segment display are common anode and are connected to port 1 of 89S52.