完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
源程序如下:
#include #include"24c02.h" #define uc unsigned char #define ui unsigned int uc code table[]= { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e//共阳极 }; int num_qian,time_qian,num_bai,time_bai,num_shi,time_shi,num_ge,time_ge,sum_qian,sum_bai,sum_shi,sum_ge,tiao,mode,time,num; long sum; ui i,j ; ***it move=P1^7; ***it add=P1^6; ***it set=P1^5; ***it jiejin=P1^4; ***it yuan=P1^3; ***it ping=P1^2; ***it led=P1^1; ***it guangqian=P3^2; ***it alarm=P1^1; void delay(ui z) { ui x,y; for(x=z;x--;x>0) for(y=12;y--;y>0); } void system_ini ( void) { ping=1; yuan=1; led =1; EA=1; EX0=1; IT0=1; x24c02_init(); num_qian=x24c02_read(1); num_bai=x24c02_read(2); num_shi=x24c02_read(3); num_ge=x24c02_read(4); sum_qian=x24c02_read(5); sum_bai=x24c02_read(6); sum_shi=x24c02_read(7); sum_ge=x24c02_read(8); time_qian=x24c02_read(9); time_bai=x24c02_read(10); time_shi=x24c02_read(11); time_ge=x24c02_read(12); num=num_ge+num_shi*10+num_bai*100+num_qian*1000; sum=sum_ge+sum_shi*10+sum_bai*100+sum_qian*1000; time=time_ge+time_shi*10+time_bai*100+time_qian*1000; } void system_led (led) { //P2=0xff ; P2=0xf7; P0=0X00 P0=table[sum_ge]; ; delay(15); //P2=0xf0; P2=0xff ; P2=0xfb; P0=0x00; P0=table[sum_shi]; delay(15); //P2=0xf0; P2=0xff ; P2=0xfd; P0=0x00; P0=table[sum_bai]; delay(15); //P2=0xf0; P2=0xff ; P2=0xfe; P0=0x00; P0=table[sum_qian]; delay(15); //P2=0xf0; P2=0xff ; } void system_set ( void ) { if(set==0) { delay(1000); if(set==0) { EA=0; tiao=1; mode++; if(mode==3) { mode=0; EA=1; } } } if(mode==0) { if(move==0) { delay(100); if(move==0) { sum_ge=0; sum_shi=0; sum_bai=0; sum_qian=0; x24c02_write(5,sum_qian); delay(10); x24c02_write(6,sum_bai); delay(10); x24c02_write(7,sum_shi); delay(10); x24c02_write(8,sum_ge); delay(10); } } system_led (led); if(sum_ge==10) { sum_ge=0; sum_shi++; if(sum_shi==10) { sum_shi=0; sum_bai++; if(sum_bai==10) { sum_bai=0; sum_qian++; if(sum_qian==10) sum_qian=0; } } } x24c02_write(5,sum_qian); delay(10); x24c02_write(6,sum_bai); delay(10); x24c02_write(7,sum_shi); delay(10); x24c02_write(8,sum_ge); delay(10); sum=sum_ge+sum_shi*10+sum_bai*100+sum_qian*1000; if((sum>=num)&(num>1)) { if(sum_ge==10) { sum_ge=0; sum_shi++; if(sum_shi==10) { sum_shi=0; sum_bai++; if(sum_bai==10) { sum_bai=0; sum_qian++; if(sum_qian==10) sum_qian=0; } } } yuan=1; P2=0xf0; for(i=1;i<=time;i++) { for(j=1;j<200;j++) { system_led (led); } } ping=1; while(jiejin==1) { led=1; for(j=1;j<100;j++) { system_led (led) ; } led=0; for(j=1;j<100;j++) { system_led (led); } } led=1; sum_ge=0; sum_shi=0; sum_bai=0; sum_qian=0; } } if(mode==1) { if(move==0) { delay(1000); if(move==0) { tiao++; if(tiao==5) tiao=1; } } if(tiao==1) { delay(10); P2=0xf7; P0=table[time_ge]; if(add==0) { delay(1000); if(add==0) { time_ge++; if(time_ge==10) time_ge=0; } } } if(tiao==2) { delay(10); P2=0xfb; P0=table[time_shi]; if(add==0) { delay(1000); if(add==0) { time_shi++; if(time_shi==10) time_shi=0; } } } if(tiao==3) { delay(10); P2=0xfd; P0=table[time_bai]; if(add==0) { delay(1000); if(add==0) { time_bai++; if(time_bai==10) time_bai=0; } } } if(tiao==4) { delay(10); P2=0xfe; P0=table[time_qian]; if(add==0) { delay(1000); if(add==0) { time_qian++; if(time_qian==10) time_qian=0; } } } x24c02_write(9,time_qian); delay(10); x24c02_write(10,time_bai); delay(10); x24c02_write(11,time_shi); delay(10); x24c02_write(12,time_ge); delay(10); time=time_ge+time_shi*10+time_bai*100+time_qian*1000; } if(mode==2) { if(move==0) { delay(1000); if(move==0) { tiao++; if(tiao==5) tiao=1; } } if(tiao==1) { delay(10); P2=0xf7; P0=table[num_ge]; if(add==0) { delay(1000); if(add==0) { num_ge++; if(num_ge==10) num_ge=0; } } } if(tiao==2) { delay(10); P2=0xfb; P0=table[num_shi]; if(add==0) { delay(1000); if(add==0) { num_shi++; if(num_shi==10) num_shi=0; } } } if(tiao==3) { delay(10); P2=0xfd; P0=table[num_bai]; if(add==0) { delay(1000); if(add==0) { num_bai++; if(num_bai==10) num_bai=0; } } } if(tiao==4) { delay(10); P2=0xfe; P0=table[num_qian]; if(add==0) { delay(1000); if(add==0) { num_qian++; if(num_qian==10) num_qian=0; } } } x24c02_write(1,num_qian); delay(10); x24c02_write(2,num_bai); delay(10); x24c02_write(3,num_shi); delay(10); x24c02_write(4,num_ge); delay(10); num=num_ge+num_shi*10+num_bai*100+num_qian*1000; } } main() { system_ini ( ) ; if (jiejin==0) //接近开关拿 { ping=1; // yuan=1; // led =1; // } while(1) { if(jiejin==1) { ping=0; yuan=0; led =1; } system_set ( ) ; } } void int0(void) interrupt 0 using 0 { sum_ge++; } 计数到一定时,为什么会出现数码管会乱码呢。。 |
|
相关推荐
4个回答
|
|
以后还是做注释吧,还要去想那参数定义的是什么,我看到后面前面的已经忘了
|
|
|
|
同感,这么长代码你求助于别人,应该带注释啊。何况这也是个好习惯,相信时间久了,你自己都会看不懂了。对不? |
|
|
|
谢谢,我知道了。。
|
|
|
|
有原理图不?!
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
277 浏览 0 评论
【敏矽微ME32G070开发板免费体验】之原厂2812测试例程解析
368 浏览 0 评论
766 浏览 2 评论
《DNESP32S3使用指南-IDF版_V1.6》第二十六章 INFRARED_RECEPTION实验
592 浏览 0 评论
879 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12035 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 01:11 , Processed in 0.676317 second(s), Total 80, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号