我想用51单片机编个倒计时的c程序,要求用两位数码管显示分钟的,并用一个按键
在设计倒计时程序时,如果数字管的1 和2 端口直接悬挂或连接,可能会出现一些问题。
建议使用两个全局变量显示个人或十位,以便在显示程序逻辑的显示和简化过程中可以避免重复计算。
编程时,您必须中断重要的答案,以控制标志变量标志的值。
该按钮可以改变三个状态:正常,休息时间和时间。
如果当前状态是第三个状态,则可以考虑重置相应的变量或使其保持不变。
计时器设置为1 0毫秒,每1 0毫秒为全球第二变量增加1 个。
当第二个变量1 00到达时,这意味着第二个。
如果第二个变量降低到0,则将第二个变量恢复为6 0,并将全局分钟的个体位减少1 如果单个位不够,则将十位减少1 ,将单个位减少到9 集。
如果十个数字没有足够的降低,则意味着时间到了,标志已设置为第三个状态。
在主函数初始化各种状态之后,它不断更新数字管中显示的数字以实现倒计时功能。
数字时钟C语言设计.用的是51单片机。
00 秒 00 分 00 小时 还有小数点。
麻烦把程序代码告诉我把
我写了一个! 用数字管显示! 您可以使用键盘检查时间! 他们指的是。
我还写了一个LCD显示器! 如果需要,可以将其发送给您! #include #deconucharunsignedchar#defuintunsignededededintsbitk1 = p3 ^0; sbitk2 = p3 ^1 ; 0x6 f}; uchhartable1 [] = {0x5 b,0x6 6 .0x6 d,0x6 f,0x6 d,0x6 f}; uchhartable2 [] = {0.1 .0.0.0}; intshi = 1 ,fen = 0,miao = 0; Uchara,i,j,temp = -2 ,temp1 ; voidsfm(uchardz,ucharshu); //将计数数字void display的十个和单个数字分开(); //替换时间显示voiddisplay1 (uchardz); //仅表示数字,即voidinit(); // voidjiaoshi(); //可以为(y = 0; y = 0; y
谁能告诉我51单片机简单的led数码管时钟程序 24小时制的(c语言版的)
#include“ reg5 2 .h”#defineUintunSignedInt#defineucharunsignedCharucharacoDetab [] = {0x3 f,0x06 ,0x5 b,0x6 6 ,0x6 d,0x7 d,0x7 d,0x7 d,0x7 d,0x7 ,0x7 f,0x6 f,0x6 f,0x6 f,0x6 f,0x6 f}; int; for(; x> 0; x-){; y ++);}}} viddisplay(ucharshi,ucharfen,ucharmiao){p2 = 0; //位代码p0 =(tab [sh/1 0]); //段代码延迟(2 ); p2 = 1 ; 标签[shi%1 0]); 延迟(2 ); p2 = 2 ; //位代码P0 = 0x4 0; //段代码延迟(2 ); p2 = 3 ; //位代码p0 =(tab [fen/1 0]); , 延迟(2 ); p2 = 5 ; //位代码P0 = 0x4 0; //段代码延迟(2 ); p2 = 6 ; //位代码p0 =(tab [miao/1 0]); //段代码延迟(2 ); p2 = 7 ; p0 =(tab [miao%1 0]); 延迟(2 );} voidmain(){tmod = 0x01 ; th0 =(6 5 5 3 6 –5 0000)/2 5 6 ; tl0 =(6 5 5 3 6 -(6 5 5 3 6 -5 0000)%2 5 6 ; ea = 1 ; et0 = 1 ; tr0 = 1 ; while(1 ){if(if(time = 2 0){time = 0; miao ++; miao ++; miyo ======== 6 0){miyo; 2 4 )shi = 0;}} display(shi,fen,miao);}/ *
51单片机6位数码管显示时间
C5 1 微控制器六位数数字管时钟用于用数字管点与三个键设置时间:设置键:设置 - 设置 - > MINUSE - > MINUSE设置 - >结束设置,两位数的数字管,代表小时设置的小时设置 状态闪烁,两位数的数字管指示分钟设置更改键时分钟闪烁:在小时设置状态和分钟设置状态设置键:将秒设置为零C语言 代码://main.c#include typeDefunSignedIntuint; typeDefunSignedCharuchar;#defineKeyp2 #definekeymask0x07 sbitle1 = p2 ^6 ; //定义位端口sbitle2 ucharkeypre ssdown = 0x00; ucharkeyrelease = 0x00; ucharlastkey = 0x00; ucharmode; externucharhh; externucharhh; externucharmm; externucharss; externbitt_cycle; externbitt_cycle; externVoidT0_Init(void); //初始化计时的数字,函数函数,函数,函数,函数,函数,函数 timer.cucharcodenum [] = {0xc0,0xf9 ,0xa4 ,0xb0,0x9 9 ,0x9 2 ,0x8 2 ,0x8 2 ,0xf8 ,0x8 0,0x9 0}; voiddelay(uintt)//延迟t时钟周期{while(t-); } voidh_increase(void)//小时增加1 {if(hh <2 3 )hh ++; else {hh = 0;}} voidm_increase(void)//分钟增加1 {if(mm <5 9 )mm ++ = 0; h_增加();}} voids_increase(void)//增加1 秒{if(ss <5 9 )ss ++; else {ss = 0; m_increase();}} voiddisplay(ucharseg,uchardigi)//显示一个单个数字管,seg = 0-9 号,digi = digi = bit 0-6 {le2 = 1 ; p0 =(0x01 << digi); le2 = 0; p0 = 0x00; le1 = 1 ; p0 = num [seg]; if(digi == 1 || digi == 3 )p0&= 0x7 f; //显示定界线 延迟(5 0); p0 = 0xff; le1 = 0;} voidmain(void){p0 = 0xff; le1 = 0; le2 = 0; t0_init(); while(1 ){if(mode!= 1 || t_cycle) {display(hh/1 0,0); //显示ten-digit显示(hh%1 0,1 ); //显示的单二与 小时} if(mode!= 2 || t_cycle){display(mm/1 0,2 ); //显示ten-digit显示(mm%1 0,3 ); // //显示单位分钟}显示(ss/1 0 ,4 ); //显示秒显示的十个数字(SS%1 0,5 ); //显示秒的单位数字}} voidkey_process(void)//键处理程序 {uCharCurrkey; key | = keymask; //设置IO对应于输入状态currkey =(〜key)&keymask; keyMask; keyPressDown =(〜lastKey)&currkey; keyRelease; keyRelease = lastKey&(〜currkey) ; lastKey = currkey; switch(keyRelease){case1 :if(mode == 2 )模式= 0; elsemode ++; break; break; case2 :if(mode == 1 )h_increase(); if(mode == 2 )m_increase() ; break; case4 :ss = 0; break; break;默认:break;}} // timer.c#include typeDefunSignedIntuint; typefunsignedIntuint; typ edefunsignedcharuchar; ucharhh; ucharhh = 1 4 ; //小时初始值UCHARMM = 2 ; // minute ucharmm = 2 ; // minute 初始值UCHARSS = 5 5 ; //第二个初始值Uintu_1 0ms = 0; // 1 0ms Count bitt_cycle = 0; 外部VoidKey_Process(void); factervoids_increase(void); voidt0_init(void){tmod&= 0xf0; tmod | = 0x01 ; //计时器分配了初始值,时间时间为1 0ms。
th0 = 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仿真电路: