STC15F2K60S2,独立按键控制一个LED灯亮和灭,在亮的时候,过了大约7或8秒会自动熄灭,有时回马上灭,哪位朋友遇到过这问题,请帮忙解决,望帮助,程序如下:
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit BZ=P2^5; //LED INPUT//
sbit D=P3^7; //KEY//
void Delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
//unsigned char temp;
void main()
{
static bit temp;
BZ=1;
//D=1;
temp=BZ;
while(1)
{
if(D==0)
{
Delay(10);
if(D==0)
{
temp=~temp;
while(D==0);
Delay(10);
BZ=temp;
}
}
}
}
|