请高手用单片机C语言编写c51时钟程序,含有6个数显管,3个按键,要自己写的,不要百度什么的复制粘贴
这就是我开始时写的。段代码连接到p1 ,t0计数*/#,其中
3 ; sbitled_5 = p2 ^4 ; sbitdp = p1 ^7 ; sbitan_mod = p2 ^5 ; sbitan_movright = p2 ^6 ; sbitan_u; p = p2 ^7 ; asta -signedCodetab [] = {0x9 0,0xd7 ,0xa2 ,0xa8 6 ,0xc5 ,0x8 c,0x8 8 ,0xd6 ,0x8 0,0x8 4 }; austy -scholarly = 0,小时= 0,minute = 0,second = 0,section = 0,section = 0,section = 1 ; // 2 0个数字不兼容。
nute_2 = 0,week_1 = 1 ; bitfire_flag = 0,adj = 0; nsignedCharmod = 0; nsignedCharled_mov = 0; /打开中断ET0 = 1 ; pt0 = 1 ; //设置T0最佳tmod = 0x01 ; // T0以1 6 位正时模式工作TH0 = 0x3 C; // 4 ; 9 9 9 6 ustl0 = 0xb7 ; tr0 = 1 ;} voddelay(assingeditus) 位闭合位显示{LED_1 = 1 ;}和{p1 = tab [hour/1 0]; LED_1 = 0; //打开1 delay(2 5 0); LED_1 = 1 ;} p1 = tab [小时[小时[小时; %1 0]; if(number <1 0){dp = 1 ;} //第二点关闭{dp = 0;} //第二点更改为led_2 = 0; = 1 ; p1 = tab [分钟/1 0]; LED_3 = 0; = 1 ; k]; LED_5 = 0; //打开5 delay(8 0); LED_5 = 1 ;} voidled_adj(){p1 = tab [hour_1 ]; LED_1 = 0; //打开1 if(led_mov == 0){delay(2 00);}和{delay(2 );} led_1 = 1 ; p1 = tab [hour_2 ]; LED_2 = 0; //打开2 if(led_mov == 1 ){delay(2 00); 延迟(2 );} LED_2 = 1 ; p1 = tab [minten_1 ]; LED_3 = 0; //打开3 IF(LED_MOV == 2 ){delay(2 00);}和{delay(2 );} LED_3 = 1 ; p1 = tab [minion_2 ]; LED_4 = 0; //打开4 IF(LED_MOV == 3 ){delay(2 00);}和{delay(2 );} led_4 = 1 ; p1 = tab [w [w [w [w [w] eek_1 ]; LED_5 = 0; //打开5 if(led_mov == 4 ){delay(5 0);}和{delay(1 );} led_5 = 1 ;} voidkeyscan(){switch(mod){case0:if(a_mod == 0)(dou ); if(a_mod == 0){mod = 1 ;} while(a_mod);} if(a_up == 0){delay(do u); }休息1 :first_flag = 0 当前的调整时间{LED_MOV = 0小时/1 0 =分钟// // Mode键= 0,请直接调整值,而没有任何更改。
拿(dou); if(an_movright == 0)调整向上的时间{delay(dou); if(a_up == 0){switch(led_mov){case0:hour_1 ++; 休息; case1 :clock_2 ++; 休息; 案例2 :minute_1 ++; 休息; 休息; k; case3 :minion_2 ++; 休息; 案例4 :week_1 ++; 休息? 延迟(dou); 如果(a_mod == 0){first_flag = 0; //重置adj = 0; mod = 0; 小时=小时_1 *1 0+hou r_2 确认后; 分钟=分钟_1 *1 0+minute_2 ; 第二个= 0; 周=周= kem = 0;} while(an_mod);} brake; 情况2 :如果(an_up == 0){delay(dou); a_up == 0){mod = 0;} while(!a_up);}}}} videcheck_num(){if(week> = 8 ){week = 1 ; } if(((hour_1 *1 0+hr_2 )> = 2 4 ){bell_1 = 0; clock_2 = 0;} if(minuse_1 > = 7 ){mince_1 = 0;} if(minne_2 > = 1 0){mince_2 = 0;}}}}}}}}} if(week_1 > = 8 ){week_1 = 1 ;} if(led_mov(led_mov) > = 5 ){LED_MOV = 0;}} voidConver(){if(num> = 2 0){seco n ++; num = 0; if(第二> = 6 0){minune ++; 第二= 0;} if(minute> = 6 0){小时++; 分钟= 0;}如果(小时> = 2 4 ){week ++; 小时= 0; } // if(hour == 2 3 && minute == 5 5 && second == 0))); while(1 ){keyscan(); , check_num();}} voidzd()Interpt1 {th0 = 0x3 c; // 4 9 9 9 6 ustl0 = 0xb7 ; num ++;}
51单片机6位数码管显示时间
C5 1 微控制器六位数微控制器管时钟用于分开数字三键管子时钟以设置时间:设置键:设置 - >> minute steters-代表每小时设置状态点火,两个数字数字点火指示确定何时打开的分钟 分钟分钟的更改:更改时钟设置条件的值并设置分钟设置键:将秒设置为零C语言代码://main.c#includecucharcodeNum [] = {0xc0.0xf9 .0xa4 .0x9 9 .0x8 2 .0x5 2 .0xf8 .0x8 0.0x9 0; ; mm = 0; h_ granning();}} voids_incree(无效)//增加管子,seg = 0-9 数字,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(无效){p0 = 0xff; le1 = 0; le2 = 0; t0_init(); while(1 ){if(mode!= 1 || t_cycle){屏幕(HH/1 0.0); //十分位数屏幕(HH%1 0.1 )屏幕; //单小时屏幕} if(mode!= 2 || t_cycle){屏幕(mm/1 0.2 ); //十分位数屏幕(mm%1 0,3 ); //表示单分钟}屏幕(SS/1 0.4 ); //显示秒数的十位数字(SS%1 0.5 ); //显示秒的单位数字}}} voidkey_process(ivebalid)//钥匙架{ucharcurkey; 键| = keymask; //设置对应于curokey =(〜key)和keymask状态键的IO; KeyPressDown =(〜lastKey)&curkey; keyLease = lastKey&(〜curkey); lastKey = curkey; keyLease){essue1 :if(mode == 2 )mode = 0; ElSemode ++; 休息; 问题2 :if(mode == 1 )h_increase(); if(mode == 2 )m_intercrease(); 休息; 问题4 :SS = 0; 破碎的; 默认:休息; EdeFunSignedCharch; ucharhh = 1 4 ; ; voidt0_init(无效){tmod&= 0xf0; tmod | = 0x01 ; //计时器确定起始值,时间的时间为1 0ms。
th0 = 0xd8 ; TL0 = 0xF0; tr0 = 1 ; ie = 0x8 2 ;} voidt0_intsrv(无效)intruption1 {//计时器再次开始时间。
th0 = 0xd8 ; TL0 = 0xF0; U_1 0MS ++; if(u_1 0ms%2 0 == 0)// 2 00m();} key_process(); //设置密钥处理} proreus仿真电路:
用C51编程实现8个数码管稳定点亮,实现显示12345678
在编程数字管时,为了获得稳定的8 个数字管照明并显示一定数量,可以用C5 1 语言编写程序。在这里,我们将以1 2 3 4 5 6 7 8 的形式作为演示的示例。
首先,将两个端口(LED_PORT和LED_CONT_PORT)定义为控制段选择和数字试管位选择。
段选择端口由LED_CONT_PORT控制,而位选择端口由LED_PORT控制。
接下来,很容易编写延迟延迟以控制数字管显示的速度。
在主要功能中,无限循环用于确保程序继续进行。
在循环中,首先设置所有位选择端口,然后设置所有段选择端口以照亮数字管。
然后,通过更改片段选择端口的不同值,将不同的数字管点亮以显示数字1 至8 在每个灯后,通过调用延迟函数来确保每个数字的显示时间为足够长的时间使显示效果更稳定。
特别是,第一个程序点亮了第一个显示数字1 的数字管,该数字通过将LED_CONT_PORT设置为0xFF和LED_PORT将其实现,并将其设置为LED_TABLE [1 ]。
然后,将位选择端口重置为0xFe,等待片刻,将位选择端口重置为0xff,然后设置端口的端口以显示数字2 ,LED_Table [2 ],然后等待一分钟。
接下来,重复上述步骤并显示诸如3 、4 、5 、6 、7 和8 之类的数字。
整个过程继续调整所选端口值以实现数字管的稳定显示。
通过上面的程序,可以达到稳定的照明8 个数字管,并显示1 2 3 4 5 6 7 8 这种编程方法简单易懂,适合初学者学习C5 1 语言显示技术和数字管。
在实际应用中,可以根据需要调整延迟延迟参数,以满足不同的显示要求。