完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
第四位是数字的十位 应该在第一位 第一位是数字的个位 应该在第二位 第二位是显示组别 应该在第四位 程序内部调换 怎么调换 位 都是乱的 除非我把底下接线改了 这是动态显示的程序 void display(uchar number,uchar second) //动态显示 { uchar second_first,second_second; second_first = second / 10; second_second = second % 10; P2 = 0xfe; P0 = table[number]; delay(2); P2 = 0xfd; P0 = 0xbf; delay(2); P2 = 0xfb; P0 = table[second_first]; delay(2); P2 = 0xf7; P0 = table[second_second]; delay(2); } 全部程序在下边 #include /*----------------------------------------------------------- 宏定义 ------------------------------------------------------------*/ #define uint unsigned int #define uchar unsigned char /*----------------------------------------------------------- 共阴极数码管编码表 0 - f显示 ------------------------------------------------------------*/ unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; /*----------------------------------------------------------- 变量定义 ------------------------------------------------------------*/ ***it buzz=P3^5; ***it start_stop = P3^6; ***it reset = P3^7; ***it key1 = P1^0; ***it key2 = P1^1; ***it key3 = P1^2; ***it key4 = P1^3; ***it key5 = P1^4; ***it key6 = P1^5; ***it key7 = P1^6; ***it key8 = P1^7; ***it state = P3^4; ***it kaishi=P3^1; bit start_stop_flag = 0; bit key1_flag = 0; bit key2_flag = 0; bit key3_flag = 0; bit key4_flag = 0; bit key5_flag = 0; bit key6_flag = 0; bit key7_flag = 0; bit key8_flag = 0; bit reset_flag = 0; bit action = 0; bit kaishi_flag=0; uchar second = 20; uchar timer0_count = 0; uchar number = 0; uchar number_display = 0; /*----------------------------------------------------------- 延时函数 ------------------------------------------------------------*/ void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } /*----------------------------------------------------------- 数码管显示驱动函数 ------------------------------------------------------------*/ void display(uchar number,uchar second) //动态显示 { uchar second_first,second_second; second_first = second / 10; second_second = second % 10; P2 = 0xfe; P0 = table[number]; delay(2); P2 = 0xfd; P0 = 0xbf; delay(2); P2 = 0xfb; P0 = table[second_first]; delay(2); P2 = 0xf7; P0 = table[second_second]; delay(2); } /*----------------------------------------------------------- 开始键扫描函数 ------------------------------------------------------------*/ void start_stop_keyscan() { if(start_stop == 0) { delay(8); if((start_stop == 0)&&(!start_stop_flag)) { start_stop_flag = 1; action = 1; TR0 = 1; state = 0; } } else { start_stop_flag = 0; } } /*----------------------------------------------------------- 八位抢答键扫描函数 ------------------------------------------------------------*/ uchar key_scan8() { if(key1 == 0) { delay(8); if((key1 == 0)&&(!key1_flag)) { key1_flag = 1; number = 1; number_display = number; } } else { key1_flag = 0; number = 0; } if(key2 == 0) { delay(8); if((key2 == 0)&&(!key2_flag)) { key2_flag = 1; number = 2; number_display = number; } } else { key2_flag = 0; number = 0; } if(key3 == 0) { delay(8); if((key3 == 0)&&(!key3_flag)) { key3_flag = 1; number = 3; number_display = number; } } else { key3_flag = 0; number = 0; } if(key4 == 0) { delay(8); if((key4 == 0)&&(!key4_flag)) { key4_flag = 1; number = 4; number_display = number; } } else { key4_flag = 0; number = 0; } if(key5 == 0) { delay(8); if((key5 == 0)&&(!key5_flag)) { key5_flag = 1; number = 5; number_display = number; } } else { key5_flag = 0; number = 0; } if(key6 == 0) { delay(8); if((key6 == 0)&&(!key6_flag)) { key6_flag = 1; number = 6; number_display = number; } } else { key6_flag = 0; number = 0; } if(key7 == 0) { delay(8); if((key7 == 0)&&(!key7_flag)) { key7_flag = 1; number = 7; number_display = number; } } else { key7_flag = 0; number = 0; } if(key8 == 0) { delay(8); if((key8 == 0)&&(!key8_flag)) { key8_flag = 1; number = 8; number_display = number; } } else { key8_flag = 0; number = 0; } if(number_display != 0) { return 1; } else { return 00; } } /*----------------------------------------------------------- 复位键扫描函数 ------------------------------------------------------------*/ void reset_keyscan() { if(reset == 0) { delay(8); if((reset == 0)&&(!reset_flag)) { second=20; reset_flag = 1; number_display = 0; state = 1; } } else { reset_flag = 0; } } /* 开机函数*/ void kaishi_keyscan() { if(kaishi == 0) { delay(8); if((kaishi == 0)&&(!kaishi_flag)) { kaishi_flag = 1; number_display = 0; second=0; state = 1; } } else { kaishi_flag = 0; } } /*----------------------------------------------------------- 主函数 ------------------------------------------------------------*/ void main() { TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=0; while(1) { while((kaishi == 0)&&(!kaishi_flag)) { start_stop_keyscan(); reset_keyscan(); while(action) { while(!key_scan8()) { display(number_display,second); if(second == 0) { second = 20; break; } } buzz=1; delay(50); TR0 = 0; second = 0; display(number_display,second); action = 0; break; } display(number_display,second); } } } /*----------------------------------------------------------- 中断服务函数 ------------------------------------------------------------*/ void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; timer0_count ++; if(timer0_count == 20) { timer0_count = 0; second --; if(second == 0) { TR0 = 0; number_display = 0; state = 1; action = 0; } } } |
|
相关推荐
3个回答
|
|
支持一下,感谢分享~~~
|
|
|
|
|
|
|
|
谁能帮着看看啊
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
298 浏览 1 评论
《DNESP32S3使用指南-IDF版_V1.6》第二十六章 INFRARED_RECEPTION实验
309 浏览 0 评论
826 浏览 0 评论
求助一下关于51系列单片机的Timer0的计时问题,TH0、TL0+1的时间是怎么算的?
1911 浏览 2 评论
【RA-Eco-RA4E2-64PIN-V1.0开发板试用】开箱+Keil环境搭建+点灯+点亮OLED
1427 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12032 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 10:15 , Processed in 0.771238 second(s), Total 75, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号