关于数码管闪烁的问题,用数码管做了数字钟,运行没有什么问题,但是加了流水灯之后,数码管会闪烁,这是怎么回事?应该怎么解决?求大佬指教!
代码如下:#include<regx51.h>
#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 m,f,s,w;//秒,分,时,计数器
uchar f_nao,s_nao;//闹钟分,时
bit flag_nao;//闹钟标志
void zuo();
void you();
void delay(uint i);
//void ledscan(uchar h,uchar m,uchar 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 h,uchar m,uchar s) reentrant
{
uchar LED[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
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(s,f,m);
if(s3 == 0)
{
if(s == 23)
s = 0;
else
s++;
while(!s3)ledscan(s,f,m);
}
}
else if(s4 == 0)
{
ledscan(s,f,m);
if(s4 == 0)
{
if(f == 59)
f = 0;
else
f++;
while(!s4)ledscan(s,f,m);
}
}
}void alarm()
{
//uchar a;
if(flag_nao)
{
if(f==f_nao&&s==s_nao)
{
while(m<=5&&flag_nao)
{
fs = ~fs;
ledscan(s,f,m);}
}
}
}
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(s,f,m);
}
void naozhong()interrupt 2
{
f_nao = f;
s_nao = s;
while(s5)
{
ledscan(s_nao,f_nao,0);
if(s3 == 0)
{
ledscan(s_nao,f_nao,0);
if(s3 == 0)
{
if(s_nao == 24)s_nao =0;
else s_nao++;
}
while(!s3) ledscan(s_nao,f_nao,0);
}
else if(s4 == 0)
{
ledscan(s_nao,f_nao,0);
if(s4 == 0)
{
if(f_nao == 59)f_nao =0;
else f_nao++;
}
while(!s4)
ledscan(s_nao,f_nao,0);
}
}
}
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(s,f,m);
tiaojie();
alarm();
//zuo();
}
}
关于数码管闪烁的问题
关于数码管闪烁的问题,用数码管做了数字钟,运行没有什么问题,但是加了流水灯之后,数码管会闪烁,这是怎么回事?应该怎么解决?求大佬指教! 代码如下:#include<regx5…