#include <reg51.h>
#include <stdio.h>
//sbit ring=P3^2;
void delay(unsigned char x)
{
unsigned char i;
while(x-->0){
for(i=0;i<75;i++);}
}
/*****************按键子程序*********************************/
unsigned char anjian(void)
{
unsigned char x,y,i,temp;
P0=0xf0;
if (P0==0xf0)
return(-1);
while(P0&0x0f!=0);
temp=P0;
for(i=1;i<5;i++){
temp=temp<<1;
if(CY==0)y=4-i;
}
temp=0xfe;
for(i=1;i<5;i++){
P0=temp;
if((P0&0xf0)!=0xf0)x=i-1;
temp=~temp;
temp=temp<<1;
temp=~temp;
}
i=x*4+y;
delay(500);
return(i);
}
main(){
char z;
//ring=0;
z=1;
while(1){
//delay(500);
z=anjian();
//ring=1;
// if(z==1)
// {//ring=0;
// z=!z;}
//}
}
}