#include<reg51.h>
/**********************************************************
//Auther:WangFei
//Time:2013.11.27
//Function: delay some time
***********************************************************/
void delay(unsigned int temp)
{
unsigned int i;
for(;i<120;i++)
{
temp--;
}
}
/*********************************************************
//Auther:WangFei
//Time:2013.11.27
//Function: To check which key is pressed
**********************************************************/
void key_scan()
{
unsigned char temp1;
P2=0XFE;
if(P2!=0XFE)
{
delay(5);
if(P2!=0XFE)
{
temp1=P2;
switch(temp1)
{
case 0xfa:P1=0X01;break;
case 0xf6:P1=0X02;break;
//default:P1=0XF3;
}
}
}
P2=0XFD;
if(P2!=0XFD)
{
delay(5);
if(P2!=0XFD)
{
temp1=P2;
switch(temp1)
{
case 0xf9:P1=0X04;break;
case 0xf5:P1=0X08;break;
//default:P1=0X0C;
}
}
}
}
/********************************************************
//Auther:WangFei
//Time:2013.11.27
//Function: Main
//Return:Void
*********************************************************/
void main()
{
P1=0;
while(1)
{
key_scan();
}
}