51单片机可调时钟

上传:lym17208 浏览: 45 推荐: 0 文件:doc 大小:219KB 上传时间:2019-04-02 13:34:51 版权申诉
#include #define uchar unsigned char #define uint unsigned int; uint aa,ee,ff,temp; uchar miao,shi,fen,num,num1,flag; uchar code table0[]={0x80,0x90,0xb0,0xc0,0xe0,0xf0}; uchar code table6[]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89}; uchar code table5[]={0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99}; u char code table4[]={0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9}; uchar code table3[]={0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9}; uchar code table2[]={0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9}; uchar code table1[]={0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9}; void delay(uchar z) { uchar x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void init() { miao=58; fen=58; shi=23; TMOD=0X11; TH1=(65536-50000)/256; TL1=(65536-50000)%6; EA=1; ET1=1; TR1=1; } void displaymiao(uchar date) { uchar shiwei,ge; shiwei=date/10; ge=date; P0=table2[shiwei]; delay(2); P0=table1[ge]; delay(2); } void displayfen(uchar date) { uchar shiwei,ge; shiwei=date/10; ge=date; P0=table4[shiwei]; delay(2); P0=table3[ge]; delay(2); } void displayshi(uchar date) { uchar shiwei,ge; shiwei=date/10; ge=date; P0=table6[shiwei]; delay(2); P0=table5[ge]; delay(2); } void keyb() { P2=0xfe; temp=P2; temp=temp&0xf8; while(temp!=0xf8) { delay(10); temp=temp&0xf8; switch(temp) { case 0xf0:num=1; break; case 0xe8:num=2; break; case 0xd8:num=3; break; } while(temp!=0xf8) { temp=P2; temp=temp&0xf8; } } P2=0xfd; temp=P2; temp=temp&0xf8; while(temp!=0xf8) { delay(10); temp=temp&0xf8; switch(temp) { case 0xf0:num=4; break; case 0xe8:num=5; break; case 0xd8:num=6; break; } while(temp!=0xf8) { temp=P2; temp=temp&0xf8; } } P2=0xfb; temp=P2; temp=temp&0xf8; while(temp!=0xf8) { delay(10); temp=temp&0xf8; switch(temp) { case 0xf0:num=7; break; case 0xe8:num=8; break; case 0xd8:num=9; break; } while(temp!=0xf8) { temp=P2; temp=temp&0xf8; } } if(num==1) { num=0; TR1=0; } if(num==2) { num=0; TR1=1; } if(num==3) { num=0; TR1=0; { fen++; if(fen==60) { fen=0; } } } if(num==4) { num=0; TR1=0; delay(50000); shi++; if(shi==24) { shi=0; } } } void main() { init(); while(1) { keyb(); if(aa==20) { aa=0; miao++; if(miao==60) { miao=0; fen++; if(fen==60) { fen=0; shi++; if(shi==24) { shi=0; } } } } displaymiao(miao); displayfen(fen); displayshi(shi); } } void timer1() interrupt 3 { TH1=(65536-50000)/256; TL1=(65536-50000)%6; aa++; } char code table4[]={0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9}; uchar code table3[]={0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9}; uchar code table2[]={0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9}; uchar code table1[]={0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9}; void delay(uchar z) { uchar x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void init() { miao=58; fen=58; shi=23; TMOD=0X11; TH1=(65536-50000)/256; TL1=(65536-50000)%6; EA=1; ET1=1; TR1=1; } void displaymiao(uchar date) { uchar shiwei,ge; shiwei=date/10; ge=date; P0=table2[shiwei]; delay(2); P0=table1[ge]; delay(2); } void displayfen(uchar date) { uchar shiwei,ge; shiwei=date/10; ge=date; P0=table4[shiwei]; delay(2); P0=table3[ge]; delay(2); } void displayshi(uchar date) { uchar shiwei,ge; shiwei=date/10; ge=date; P0=table6[shiwei]; delay(2); P0=table5[ge]; delay(2); } void keyb() { P2=0xfe; temp=P2; temp=temp&0xf8; while(temp!=0xf8) { delay(10); temp=temp&0xf8; switch(temp) { case 0xf0:num=1; break; case 0xe8:num=2; break; case 0xd8:num=3; break; } while(temp!=0xf8) { temp=P2; temp=temp&0xf8; } } P2=0xfd; temp=P2; temp=temp&0xf8; while(temp!=0xf8) { delay(10); temp=temp&0xf8; switch(temp) { case 0xf0:num=4; break; case 0xe8:num=5; break; case 0xd8:num=6; break; } while(temp!=0xf8) { temp=P2; temp=temp&0xf8; } } P2=0xfb; temp=P2; temp=temp&0xf8; while(temp!=0xf8) { delay(10); temp=temp&0xf8; switch(temp) { case 0xf0:num=7; break; case 0xe8:num=8; break; case 0xd8:num=9; break; } while(temp!=0xf8) { temp=P2; temp=temp&0xf8; } } if(num==1) { num=0; TR1=0; } if(num==2) { num=0; TR1=1; } if(num==3) { num=0; TR1=0; { fen++; if(fen==60) { fen=0; } } } if(num==4) { num=0; TR1=0; delay(50000); shi++; if(shi==24) { shi=0; } } } void main() { init(); while(1) { keyb(); if(aa==20) { aa=0; miao++; if(miao==60) { miao=0; fen++; if(fen==60) { fen=0; shi++; if(shi==24) { shi=0; } } } } displaymiao(miao); displayfen(fen); displayshi(shi); } } void timer1() interrupt 3 { TH1=(65536-50000)/256; TL1=(65536-50000)%6; aa++; }
上传资源
用户评论
相关推荐
单片机51数字时钟可调按键
本例子是用51单片机来实现数字时钟 用按键来可调时间的程序源代码
C
0B
2019-02-18 16:12
基于51单片机可调时钟程序
基于51单片机的时钟程序,能够通过键盘调节时间,精确到秒
RAR
0B
2018-12-27 15:52
51单片机可调电子时钟
采用1602液晶显示,年月日,星期,时分秒都有显示并且实现时间可自行调准,误差1日小于1分钟
APPLICATION/X-RAR
1KB
2020-08-20 19:33
基于51单片机可调电子时钟
利用单片机设计电子时钟,编程用c语言,秒表、时钟计时器要求用液晶1602显示时、分、秒。使用按键开关可实现时分调整、秒表/时钟功能
C
5KB
2020-11-24 12:03
基于51单片机可调电子时钟.zip
利用51单片机做的时钟,显示时分秒,通过三个按键可对时钟时间进行设置,程序非常简单适合新手入门及小制作
ZIP
112KB
2020-10-19 20:12
单片机可调时钟
单片机编程可调时钟详细源代码运行无错误
ZIP
0B
2019-02-18 01:34
51汇编设计可调时钟秒表
用51汇编设计可调时钟秒表,详细分析、电路图、程序
PDF
0B
2019-05-02 21:39
51单片机1602显示可调时钟源程序及仿真
在51单片机上面连接1602显示屏,并实现的可调时钟的源程序和仿真。
RAR
0B
2019-05-25 04:14
51单片机的定时器可调时钟源程序
基于定时器T0的可调时钟 LSA=>P2^2; LSB=>P2^3; LSC=>P2^4; P0=>数码管位选 P3=>独立按键 数码管从00-00-00 (时-分-秒)
C
5KB
2020-08-17 23:43
可调时钟
单片机可调时钟,二十四小时计时,可调节小时,分钟
C
0B
2019-07-29 23:24
单片机可调电子时钟
包含完整的工程,有完整的代码和注释,以及仿真的电路图设计
RAR
0B
2019-01-04 07:47
单片机时钟显示不可调
MCU clock display (not adjustable)
C
0B
2019-06-23 02:42
52单片机定时可调时钟
基于52单片机的定时倒计时钟。
C
0B
2020-06-10 19:31
51单片机脉冲可调
51单片机脉冲可调程序带1602显示.C语言
UV2
0B
2019-07-15 22:15
51单片机制作诺基亚5110时间可调时钟
学习学习51单片机制作诺基亚5110时间可调的时钟。希望大家有所收获
DOC
0B
2019-04-06 01:39