51单片机6位数码管显示时间
C5 1 微控制器六位数数字管时钟用于用数字管点与三个键设置时间:设置键:设置 - 设置 - > MINUSE - > MINUSE设置 - >结束设置,两位数的数字管,代表小时设置的小时设置 状态闪烁,两位数的数字管指示分钟设置更改键时分钟闪烁:在小时设置状态和分钟设置状态设置键:将秒设置为零C语言 代码://main.c#includeth0 = 0xd8 ; tl0 = 0xf0; tr0 = 1 ; ie = 0x8 2 ;} voidt0_intsrv(void)interrupt1 {//计时器再次开始计时。
th0 = 0xd8 ; tl0 = 0xf0; u_1 0ms ++; if(u_1 0ms%2 0 == 0)// 2 00ms {t_cycle =!t_cycle; // flashing loop} if(u_1 0ms> 9 9 )// 1 000ms = 1 second = 1 second {u_1 0ms = 1 second {u_1 0ms = 0; s_increase ();} key_process(); //设置键 处理} proreus仿真电路:
单片机控制8位数码管,显示年月日和时分秒,但是这两者该如何切换呢?
有两种改变的方法。一个是手册。
这意味着使用该按钮每月显示一个月和一天。
然后单击以显示时钟,然后按。
再次按。
另一个是自动切换的。
它可以在几秒钟内及时显示。
请注意,小时和温度表面可以在运输车上自动转换。
单片机控制多位数码管的电子时钟程序
使用微控制器检查多个数字管的电子时钟并使用独立按钮来控制它,该按钮可以查看时间和日期并具有警报功能。Keil Engineering C语言代码: /**** ****************************************数字管:现在显示数字管的日期,可以调整小时和日期,并可以设置警报,并发出警报声音一分钟。
*************************特定tt,t,numdu,set,aclock,rili; unsignedlongintime,time1 = 0; unsignedlongintacond,现在,现在,年= 2 01 2 ,月= 1 2 ,day = 3 1 ; uchaccodedu [] = {0x3 f,0x06 .0x5 b,0x4 f,0x6 6 .0x6 d,0x7 d,0x07 .0x7 f,0x6 6 f,0x7 7 .0x7 c,0x3 9 .0x5 e [uChacodeWewe [uCharCodoDewe [uCharCodoDewe [Ucharcododewe [ucharcododeweewe] [uchacodewewew [ucharcododewe [ucharcodewe [ucharcodewe; ] = {0xfe,0xfd,0xfb,0xf7 ,0xef,0xdf,0xbf,0x7 f}; Ucharmth [1 3 ] = {0.3 1 ,2 8 ,3 1 .3 0,3 1 .3 0,3 1 .3 1 ,3 0,3 1 .3 0,3 1 }; //每月ucharymth [1 3 ] = {0.2 ,9 ,2 ,1 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,2 ,1 ,1 ,1 ,2 }的相应天数; ; sbitbeep = p2 ^2 ; // ring voiddelay(uintdel); //显示显示延迟程序(UINSD,UINTMM,UINTHY); //显示voidadd()程序; //添加vaidalarmclock(); // amerge clock voidinit(); //初始化intclock(); //计算时间voidCalender(); // voidmain计算日期(){p2 = 0xff; init(); 而(1 ){add(); 如果(rili == 1 )//日期日历和时间显示(日,月,年); Elsedisplay(第二,分钟,现在); alarmecllock();}}} vouddisplay(uintsd,uintmm,uinthy){inty0,y1 ,y2 ; 如果(rili == 1 ){y0 = hy/1 000,y1 = hy%1 000; y2 = hy%1 00;} per(numwe = 0; numwe8 ; numwe ++){p0 = 0xff; wela = 1 ; p0 =我们[number]; wela = 0; p0 = 0xff; dula = 1 ; switch(numwe){cause0:p0 =(tt == 1 set == 1 )? 0x00 :( rili == 1 )? du [y0]:du [hy/1 0]; 休息; case1 :p0 =(tt == 1 set == 2 )? 0x00 :( rili == 1 )? DU [Y1 /1 00]:DU [HY%1 0]; 休息; case2 :p0 =(rili!= 1 )? 0x4 0 :( tt == 1 set == 3 )? 0x00:du [y2 /1 0]; 休息; CAS E3 :p0 =(tt == 1 set == 4 )? 0x00 :( rili == 1 )? DU [HY%1 0]+0x8 0:DU [mm/1 0]; 休息; case4 :p0 =(tt == 1 set == 5 )? 0x00 :( rili == 1 )? DU [mm/1 0]:du [mm%1 0]; 休息; case5 :p0 =(rili!= 1 )? 0x4 0 :( tt == 1 set == 6 )? 0x00:dU [mm%1 0]+0x8 0; 休息; case6 :p0 =(tt == 1 set == 7 )? 0x00:DU [SD/1 0]; 休息; case7 :p0 =(?trusomat 5 mstl0 =(6 5 5 3 6 -5 0000)%2 5 6 ; //低计时器8 位ie = 0x8 f; //打开中断tcon = 0x1 5 ; //启动计时器和工作模式} intclock(intclock()//计算时间{if(t == 1 0 | t == 2 0)tt =! if(t == 2 0){t = 0; 2 4 ){time = 0;}}} else {second = time1 %6 0;}}}}}}}}}} voiddelay(uintdel){uinti,j; (j = 0; j1 00; j ++);} vouptimer0()intruption1 //计时器0中断{th0 =(6 5 5 3 6 -5 0000)/2 5 6 ; Interrupt0 // it0 {if(key0 == 0){delay(2 ); key0);}}}} voidCalendar()interrupt2 / / calendar {if(key3 == 0){delay(2 ); 如果(key3 == 0)rili =! rili; set = 0; aclock = 0;}}} voidCalender()//计算日历{if(time = = 8 6 4 00){day ++; if(((年%4 == 0年%1 00!= 0)|(年%4 00 == 0))mth [2 ] = 2 9 ; Elsemth [2 ] = 2 8 ; if(天[月]){day = 1 ; 一个月++; 如果(月1 2 ){月= 1 ; year ++;}}}}} vaidadd()//添加一个{intge,ge1 ,ge2 ,shi,shi,shi1 ,shi2 ,shi2 ,bai2 ,qian2 ; if(rili == 1 ){ge = day%1 0; ge1 = mo nth%1 0; GE2 =年%1 0; shi =天/1 0; shi1 =月/1 0; shi2 =年%1 00/1 0; bai2 =年%1 000/1 00; Qian2 = Year/1 000;} else {ge =第二%1 0; GE1 =分钟%1 0; GE2 =小时1 0; shi =第二/1 0; shi1 =分钟/1 0; shi2 = hour/1 0;} if(key1 == 0){delay(2 ); if(ke y1 == 0){if(rili == 1 ){if((((eNem%4 == 0年1 00!= 0))|(年%4 00 == 0))ymth [2 ] = 1 0; Elseymth [2 ] = 9 ; switch(set){case1 :qian2 =(qian2 +1 )%1 0; 休息; case2 :bai2 =(bai2 +1 )%1 0; 休息; case3 :shi2 =(shi2 +1 )%1 0; 休息; 案例4 :GE2 =(GE2 +1 )%1 0; 休息; case5 :shi1 =(shi1 +1 )%2 ; 休息; case6 :ge1 =(shi1 == 1 )? (GE1 +1 )%3 :(GE1 +1 )%1 0; 休息; case7 :shi =(月== 2 )? (SHI+1 )%3 :(SHI+1 )%4 ; 休息; case8 :ge =(shi == 3 )? (ge+1 )%ymth [月] :(月== = 2 )? (GE+1 )%ymth [2 ] :( GE+1 )%1 0; 暂停;}年= Qian2 *1 000+bai2 *1 00+shi2 *1 0+ge2 ; 月= SHI1 *1 0+GE1 ; 休息; 案例2 :GE2 =(GE2 +1 )%4 ; 休息; case4 :shi1 =(shi1 +1 )%6 ; 休息; 案例5 :GE1 =(GE1 +1 )%1 0; 休息; CAS E7 :shi =(是+1 )%6 ; 休息; 案例8 :GE =(GE+1 )%1 0; 休息;} second = shi*1 0+ge; 分钟= shi1 *1 0+ge1 ; 小时= shi2 *1 0 +ge2 ; if(aclock == 0)时间=现在*3 6 00+分钟*6 0+秒; ElSetime1 =现在*3 6 00+minute*6 0+sect;} while(!key 1 );}}}}}}}}}}} vaidalarmClock()//设置alarm arlard {if(key2 == 0){delays(delays(2 ); if(key2 == 0){while(!key2 ); 时钟= 1 ; rili = 0; set = 0; 而(1 ){if(rili == 1 )显示(日,月,年); Elsedisplay(第二,分钟,现在); 添加 (); if(key2 == 0){while e(!key2 ); 时钟= 0; set = 0; break;}}}}}}}引脚连接指令:1 Portapo porta 8 是一个常见的负数字管; 分别拘留片段和管子的位; 它可以选择警报,日期和时间。
: