#include <reg51.h>
#include "delay.h"
sbit k1 = P2 ^ 4;
sbit k2 = P2 ^ 5;
sbit k3 = P2 ^ 6;
unsigned char key()
{
unsigned char i, k;
for(i = 0; i < 4; i++)
{
P2 = ~(0x01<<i);
delay(2);
if(k1 == 0)
{
delay(2);
while(k1 == 0);
delay(2);
k = 1 + i * 3;
}
if(k2 == 0)
{
delay(2);
while(k2 == 0);
delay(2);
k = 2 + i * 3;
}
if(k3 == 0)
{
delay(2);
while(k3 == 0);
delay(2);
k = 3 + i * 3;
}
}
return k;
}
|