3226 views|0 replies

3

Posts

0

Resources
The OP
 

Button control water flow light: press key1, LED1-8 will flow in sequence, press key2, LED1/3/5/7 (4 intervals)... [Copy link]

It is stipulated that delay functions cannot be used, only timers can be used

Please help me find out what is wrong. It didn't work in the end.

#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();
}
}
}

This post is from 51mcu
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list