#include<reg52.h>
sbit key_1 = P1^0;
sbit key_2 = P1^1;
bit key_evein ;
void key_scan()
{
unsigned int mode, count;
// mode =0;
// count =0;
switch(mode)
{
case 0:
if(!key_1)
{
mode = 1;
P0=0x55;
}
break;
case 1:
if(key_1==0)
{
count++;
if(count>50)
{
count = 0;
mode=2;
}
}
else if (key_1)
{
mode=0;
}
break;
case 2:
if(key_1)
{
P3=0xf0;
mode=0;
}
else if(key_1)
{
mode = 4;
}
break;
case 4:
if(key_1==0)
{
count++;
if(count==5000)
{
count = 0;
mode = 5;
}
}
break;
case 5:
if(key_1)
{
P3=0x0f;
mode=0;
}
}
}
void main ()
{
TMOD = 0x01;
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
TR0 = 1;
EA = 1;
ET0= 1;
while (1)
{
if(key_evein) key_scan();
}
}
void timer (void ) interrupt 1
{
TR0 = 0;
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
TR0 =1;
key_evein=1;
}
|