用数码管做了数字钟,运行没有什么问题,但是加了流水灯之后,数码管会闪烁,这是怎么回事?应该怎么解决?求大佬指教!
代码如下:#include
#define uint unsigned int
#define uchar unsigned char
sbit s1 = P3^2;//闹钟开关
sbit s2 = P3^3;//设置
sbit s3 = P3^4;//小时键
sbit s4 = P3^5;//分
sbit s5 = P3^6;//退出键
sbit fs = P3^0;//蜂鸣器
sbit d = P3^1;//小灯
unsigned char mfsw;//秒,分,时,计数器
uchar f_naos_nao;//闹钟分,时
bit flag_nao;//闹钟标志
void zuo();
void you();
void delay(uint i);
//void ledscan(uchar huchar muchar s);
void alarm();
void
tiaojie();
void delay(uint i)
{
while(i--);
}
void zuo()
{unsigned char d;
unsigned char a = 0x01;
for(d = 0;d<8;d++)
{
P0 = ~a;
delay(1);
a = a<<1;
}
if(a == 0)
{
a = 0x01;
}
}
void ledscan(uchar huchar muchar s) reentrant
{
uchar LED[]={0x3f0x060x5b0x4f0x660x6d0x7d0x070x7f0x6f};
uint j;
P1 = LED[s%10];
P2 = 0x7f;
for(j = 0;j<100;j++);
P2 = 0xff;
P1 = LED[s/10];
P2 = 0xbf;
for(j = 0;j<100;j++);
P2 = 0xff;
P1 = 0x40;
P2 = 0Xdf;
for(j = 0;j<100;j++);
P2 = 0xff;
P1 = LED[m%10];
P2 = 0xef;
for(j = 0;j<100;j++);
P2 = 0xff;
P1 = LED[m/10];
P2 = 0xf7;
for(j = 0;j<100;j++);
P2 = 0xff;
P1 = 0x40;
P2 = 0xfb;
for(j = 0;j<100;j++);
P2 = 0xff;
P1 = LED[h%10];
P2 = 0xfd;
for(j = 0;j<100;j++);
P2 = 0xff;
P1 = LED[h/10];
P2 = 0xfe;
for(j = 0;j<100;j++);
P2 = 0xff;
}
void tiaojie()
{
if(s3 == 0)
{
ledscan(sfm);
if(s3 == 0)
{
if(s == 23)
s = 0;
else
s++;
while(!s3)ledscan(sfm);
}
}
else if(s4 == 0)
{
ledscan(sfm);
if(s4 == 0)
{
if(f == 59)
f = 0;
else
f++;
while(!s4)ledscan(sfm);
}
}
}void alarm()
{
//uchar a;
if(flag_nao)
{
if(f==f_nao s==s_nao)
{
while(m<=5 flag_nao)
{
fs = ~fs;
ledscan(sfm);}
}
}
}
void t0() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
w++;
if(w == 20)
{
w = 0;
m++;
if(m == 60)
{
f++;
m = 0;
if(f == 60)
{s++;
f = 0;
if(s == 24)
s = 0;}
}
}zuo();
}
void guan_naozhong() interrupt 0
{
flag_nao = ~flag_nao;
d = ~d;
while(!s1)ledscan(sfm);
}
void naozhong()interrupt 2
{
f_nao = f;
s_nao = s;
while(s5)
{
ledscan(s_naof_nao0);
if(s3 == 0)
{
ledscan(s_naof_nao0);
if(s3 == 0)
{
if(s_nao == 24)s_nao =0;
else s_nao++;
}
while(!s3) ledscan(s_naof_nao0);
}
else if(s4 == 0)
{
ledscan(s_naof_nao0);
if(s4 == 0)
{
if(f_nao == 59)f_nao =0;
else f_nao++;
}
while(!s4)
ledscan(s_naof_nao0);
}
}
}
void main()
{
TMOD = 0X01;
TH0 =(65536 - 50000)/256;
TL0 =(65536 - 50000)%256;
TR0 = 1;
ET0 = 1;
IT1 = 1;
IT0 = 0;
EX1 = 1;
EX0 = 1;
PT0 = 1;
EA = 1;
f = 0;
m = 0;
fs = 0;
flag_nao = 0;
while(1)
{
ledscan(sfm);
tiaojie();
alarm();
//zuo();
}
}
0