按键控制流水灯:按下key1,LED1-8依次进行流水,按下key2,LED1/3/5/7(间隔的4个...
[复制链接]
规定不能用延时函数,只能用定时器
各位帮忙看看哪错了, 最后没有运行效果
#include <STC12C5A60S2.H>
unsigned int Count_disturb = 0; //¼ÇÖжϴÎÊý
unsigned char key1, key2;//¼Ç¼üÖµ
unsigned int nDelay_Key = 0;
bit bLoose = 0;
void Alarm_T0() interrupt 1//¶¨Ê±Æ÷
{
TH0 = -9;//Öظ³³õÖµ
Count_disturb++;//ÖжϴÎÊý
if (nDelay_Key == 0)
{
key1 = P2 & 0x07;
if (key1 != 0x07)
{
nDelay_Key = 4;
}
else
{
bLoose = 0;
}
}
else
{
if (--nDelay_Key == 0)
{
key2 = P2 & 0x07;
if (key1 != key2)
{
key2 = 0;
}
}
}
}
void Dispose_Key()//°´¼ü´¦Àí
{
unsigned char i = 0;
if (bLoose == 0)
{
if (key2 == 0x06)//°´ÏÂP20´¦°´¼ü£¨°´¼ü1£©
{
if (Count_disturb == 200)
{
P0 = 0x03 << i++;
i = i & 7;
Count_disturb = 0;
}
}
else if (key2 == 0x05)//°´ÏÂP21´¦°´¼ü£¨°´¼ü2£©
{
if (Count_disturb == 200)
{
P0 = 0x55 & 0x01 << i++;
i = i & 7;
Count_disturb = 0;
}
}
else if (key2 == 0x03)//°´ÏÂP22´¦°´¼ü£¨°´¼ü3£©
{
if (Count_disturb == 200)
{
P0 = 0x01 << i++;
i = i & 7;
Count_disturb = 0;
}
bLoose = 1;
}
}
}
void main()
{
P0M0 = 0xff;
TMOD = 0x01;
TH0 = -9;
ET0 = 1;
TR0 = 1;
EA = 1;
while (1)
{
if (key2 != 0)
{
Dispose_Key();
}
}
}
|