完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
用数码管做了数字钟,运行没有什么问题,但是加了流水灯之后,数码管会闪烁,这是怎么回事?应该怎么解决?求大佬指教!
代码如下:#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(); } } |
|
相关推荐
1个回答
|
|
刷新率不够,或者置位方式不恰当,造成数据位都是先清除后置位。可以看看具体显示函数处理方式是否可以调整。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
644 浏览 0 评论
求助一下关于51系列单片机的Timer0的计时问题,TH0、TL0+1的时间是怎么算的?
1819 浏览 1 评论
【RA-Eco-RA4E2-64PIN-V1.0开发板试用】开箱+Keil环境搭建+点灯+点亮OLED
1262 浏览 0 评论
【敏矽微ME32G070开发板免费体验】使用coremark测试敏矽微ME32G070 跑分
1136 浏览 0 评论
【敏矽微ME32G070开发板免费体验】开箱+点灯+点亮OLED
1357 浏览 2 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12031 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 20:35 , Processed in 0.623708 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号