完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
倒计时: 低级版没有闪
用单片机的时间中断器(TR0-TR1)来进行计时来接近现实时间 #include #define uc8 unsigned char ***it k1 = P3^4; ***it k2 = P3^5; ***it k3 = P3^6; ***it k4 = P3^7; bit db; ***it led1 = P2^4; ***it led2 = P2^5; ***it led3 = P2^6; ***it led4 = P2^7; uc8 i,sh = 0,bh = 0,m = 0,sm = 5,gf = 1,sf=0,ph = 0,count_num=0; unsigned char code xianshi[]={0x8f,0x4f,0x2f,0x1f};//ÊýÂë¹Ü¸÷λµÄÂë±í unsigned char code meidian[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//ÊýÂë¹Ü¸÷λµÄÂë±í(´øÉÏСµã) unsigned char code youdian[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef}; unsigned int value = 0; unsigned int value_conut = 0; void delay(unsigned char jk){ unsigned char j,k; for(j=jk;j>0;j--) for(k=112;k>0;k--); } void delay1(unsigned int jk){ unsigned int j,k; for(j=jk;j>0;j--) for(k=112;k>0;k--); } void display1(uc8 wei,uc8 shu)//ÔÚÈÎÒâһλÏÔʾÈÎÒâµÄÊý×Ö { wei=wei-1; P2 |= 0xf0;//¸øP2.4-P2.7ÖÃ1 if(wei == 2) P0=youdian[shu]; else P0=meidian[shu]; P2=P2&xianshi[wei];//¸øP2ÐèÒªÏÔʾµÄÄÇһλÖÃ1£¬ÆäËûÖÃ0 delay(1); } void display(unsigned char a,unsigned char b,unsigned char c,unsigned char d){ //Ò»´ÎÏÔʾ4¸öÊý×Ö£¬ÇÒÿλÏÔʾÊý×Ö¿É×Ô¶¨¡£ display1(4,a); display1(3,b); display1(2,c); display1(1,d); } //void start_timer(){ // EA=1; //¿ª×ÜÖÐ¶Ï // ET0=1; //¿ª¶¨Ê±Æ÷0ÖÐ¶Ï // TR0=1; //´ò¿ª¶¨Ê±Æ÷ //} //void stop_timer(){ // ET0=0; //¹Ø¶¨Ê±Æ÷0ÖÐ¶Ï // EA=0; //¹Ø×ÜÖÐ¶Ï // TR0=0; //¹Ø±Õ¶¨Ê±Æ÷ //} void main() { TMOD = 0x01; TH0 = 0x0Dc; TL0 = 0x009; EA=1; //¿ª×ÜÖÐ¶Ï ET0=1; //¿ª¶¨Ê±Æ÷0ÖÐ¶Ï while(1){ // 按钮判断 if(!k1 && !db) { db = 1; TR0 = ~TR0; }else if(k1) { db = 0; } if(TR0) { P1 = 0xfe; }else { P1 = 0xff; } /* if(k1 == 0) { delay1(4); if(k1 == 0) count_num++; if(count_num == 1) { start_timer(); P1 = 0xf0; }else if(count_num == 2) { stop_timer(); P1 = 0x0f; }else if(count_num == 3){ count_num = 1; start_timer(); P1 = 0xf0; } } */ /* if(k3 == 0){ // TMOD = 0x10; TH1 = 0x3C; TL1 = 0x0B0; ET1 = 1; TR1 = 1; if(k3 == 0 ) { if(value >= 60) { stop_timer(); P1 = 0x0f; sf=0; gf=1; sm=5; m=0; count_num = 0; }else { ET1 = 0; TR1 = 0; value = 0; } } } */ if(k3 == 0){ if(value >= 280){ if(k3 == 0) { TR0 = 0; gf=1; sm=5; m=0; count_num = 0; value = 0; }else { value = 0; } } } if(gf == 0 && sm == 0 && m == 0) { P1 = 0xff; } //µ¹Êý¼Æʱ if(value < 277) { if(i == 1) { if(sh == 0) { if(bh == 0) { if(m == 0) { if(sm == 0) { if(gf == 0) { if(sf == 0) { P1 = 0xff; }else { sf--; gf = 10; } } else { gf--; sm = 10; } } else { sm--; m = 10; } } else { m--; bh = 10; } } else { bh--; sh= 10; } } else sh--; i = 0; } } display(sf,gf,sm,m); } } void Timer0Interrupt(void) interrupt 1 { TH0 = 0x0Dc; TL0 = 0x009; i++; if(k3 == 0) { value++; } //add your code here! } 倒计时: 高配版 有闪 倒计时到最后十秒进行闪烁 #include ***it led1 = P2^4; ***it led2 = P2^5; ***it led3 = P2^6; ***it led4 = P2^7; ***it k1 = P3^4; ***it k2 = P3^5; int lhj = 0,value = 0,i = 0, value_number = 0, smg1_light = 5, smg2_light = 2, smg3_light = 0, smg4_light = 0,flag = 0; bit db; unsigned char code light[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; void delay(unsigned int x) { unsigned int i,j; for(i = x;i > 0;i--){ for(j = 112;j > 0;j--){}; } } void main() { int value_fuzhi = 0; TMOD = 0x01; // TH0 = 0x0Dc; // TL0 = 0x009; TH0 = 0x3C; TL0 = 0x0B0; EA=1; //¿ª×ÜÖÐ¶Ï ET0=1; //¿ª¶¨Ê±Æ÷0ÖÐ¶Ï while(1){ if(!k1 && !db) { db = 1; TR0 = ~TR0; }else if(k1) { db = 0; } if(TR0) { P1 = 0xfe; }else { P1 = 0xff; } if(i == 20) { i = 0; smg1_light--; } if(smg1_light < 0) { smg2_light--; smg1_light = 9; } if(smg1_light == 0 && smg2_light == 1) { flag++; } // ¹Ø±ÕÏÔʾ if(smg1_light >= 0 && smg2_light == 1 || flag && value <= 4) { led4 = 0; led3 = 0; led2 = 0; led1 = 0; delay(1); } // ¿ªÆôÏÔʾ if(smg1_light >= 0 && smg2_light == 1 || smg2_light == 0 && value > 4 && value <= 10) { P0 = light[smg1_light]; P2 = 0x88; delay(1); P0 = light[smg2_light]; P2 = 0x48; delay(1); P0 = light[smg3_light]; P2 = 0x28; delay(1); P0 = light[smg4_light]; P2 = 0x18; delay(1); } if(lhj >= 20) { TR0 = 0; smg1_light = 5, smg2_light = 2, smg3_light = 0, smg4_light = 0; } if(smg1_light >= 0 && smg2_light > 1 || smg2_light == 0 && smg1_light < 0) { P0 = light[smg1_light]; P2 = 0x88; delay(1); P0 = light[smg2_light]; P2 = 0x48; delay(1); P0 = light[smg3_light]; P2 = 0x28; delay(1); P0 = light[smg4_light]; P2 = 0x18; delay(1); } } } void Timer0Interrupt(void) interrupt 1 { TH0 = 0x3C; TL0 = 0x0B0; i++; if(flag) { value++; } if(value > 10) { value = 0; } if(smg1_light == 0 && smg2_light == 0 && smg3_light == 0 && smg4_light == 0 ) { lhj++; } if(lhj > 20) { lhj = 0; } //add your code here! } |
|
|
|
只有小组成员才能发言,加入小组>>
3294 浏览 9 评论
2970 浏览 16 评论
3473 浏览 1 评论
9023 浏览 16 评论
4061 浏览 18 评论
1140浏览 3评论
589浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
579浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2313浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1876浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-4 02:19 , Processed in 1.190602 second(s), Total 79, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号