数字时钟程序(完整版)

合集下载

单片机制作数字钟(含万年历、秒表功能)

单片机制作数字钟(含万年历、秒表功能)

数字钟、万年历制作(基于单片机)电路原理图:程序://********************20131206****数字钟程序#pragma SMALL#include <reg51.h>#include <absacc.h>#include <intrins.h>//********************************************************* *********编译预处理void display(unsigned char *p); //显示函数,P为显示数据首地址unsigned char keytest(); //按键检测函数unsigned char search(); //按键识别函数void alarm(); //闹钟判断启动函数void ftion0(); //始终修改函数void ftion1(); //闹钟修改函数void ftion3(); //日期修改函数void cum(); //加1修改函数void minus(); //减1修改函数void jinzhi(); //进制修改函数void riqi(); //日期void stopwatch(); //秒表函数//********************************************************* *******函数声明sbit P2_7=P2^7;//********************************************************* *******端口定义unsigned char clockbuf[3]={0,0,0};unsigned char bellbuf[3]={0,0,0};unsigned char date[3]={1,1,1}; //日期存放数组unsigned char stop[3]={0,0,0};unsigned char msec1,msec2;unsigned char timdata,rtimdata,dtimdata;unsigned char count;unsigned char *dis_p;unsigned char or; //12进制控制标志unsigned char ri; //日期显示控制标志位unsigned char mb; //秒表控制标志位bit arm,rtim,rhour,rmin,hour,min,sec,day,mon,year; //定义位变量//********************************************************* *****全局变量定义void main(){unsigned char a;or=0; //12进制修改标志清零ri=0;mb=0;P2_7=0;arm=0;msec1=0;msec2=0;timdata=0;rtimdata=0;count=0;TMOD=0x12;TL0=0x06;TH0=0x06;TH1=(65536-10000)/256;TL1=(65536-10000)%256;EA=1;ET0=1;ET1=1;TR0=1;TR1=0;dis_p=clockbuf;while(1){a=keytest();if(a==0x78) //判断是否有键按下{display(dis_p);if(arm==1) alarm();}else{display(dis_p);a=keytest();if(a!=0x78){a=search();switch(a){case 0x00:ftion0();break;case 0x01:ftion1();break;case 0x02:cum();break;case 0x06:jinzhi();break;case 0x03:riqi();break;case 0x04:ftion3();break;case 0x05:minus();break;case 0x07:stopwatch();break;case 0x09:TR1=1;break;case 0x0a:TR1=0;break;case 0x0b:stop[0]=0;stop[1]=0;stop[2]=0;break;default:break;}}}}}//********************************************主函数【完】void display(unsigned char *p){unsigned char buffer[]={0,0,0,0,0,0};unsigned char k,i,j,m,temp;unsigned char led[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};buffer[0]=p[0]/10;buffer[1]=p[0]%10;buffer[2]=p[1]/10;buffer[3]=p[1]%10;buffer[4]=p[2]/10;buffer[5]=p[2]%10;if((sec==0)&&(min==0)&&(hour==0)&&(rmin==0)&&(rhour==0)&&( day==0)&&(mon==0)&&(year==0)) //没有修改标志,正常显示{for(k=0;k<3;k++){temp=0x01;for(i=0;i<6;i++){P0=0x00; //段选端口j=buffer[i];P0=led[j];P1=~temp; //位选端口temp<<=1;for(m=0;m<200;m++);}}}else //若有修改标志,则按以下标志分别显示{if(sec==1||day==1){P1=0x1f;i=buffer[5];P0=led[i];for(m=0;m<200;m++);P1=0x2f;j=buffer[4];P0=led[j];for(m=0;m<200;m++);}if(min==1||rmin==1||mon==1){P1=0x3b;i=buffer[2];P0=led[i];for(m=0;m<200;m++);P1=0x37;j=buffer[3];P0=led[j];for(m=0;m<200;m++);}if(hour==1||rhour==1||year==1) {P1=0x3e;i=buffer[0];P0=led[i];for(m=0;m<200;m++);P1=0x3d;j=buffer[1];P0=led[j];for(m=0;m<200;m++);}}}//**********************************LED显示函数【完】unsigned char keytest(){unsigned char c;P2=0x78; //检测是否有键按下c=P2;c=c&0x78;return(c);}//******************************************键盘检测函数【完】unsigned char search(){unsigned char a,b,c,d,e;c=0x3f;a=0; //行号while(1){P2=c;d=P2;d=d&0x07;if(d==0x03){b=0;break;} //列号else if(d==0x05){b=1;break;}else if(d==0x06){b=2;break;}a++;c>>=1;if(a==5){a=0;c=0x3f;}}e=a*3+b;do{display(dis_p);}while((d=keytest())!=0x78);return(e);}//***********************************************查键值函数【完】void alarm(){if((clockbuf[0]==bellbuf[0])&&(clockbuf[1]==bellbuf[1])){P2_7=1;rtim=1;if(count==10){count=0;P2_7=0;arm=0;rtim=0;}}}//****************************************闹钟判断启动函数【完】void ftion0(){TR0=0;rhour=0;rmin=0;dis_p=clockbuf;rtimdata=0;timdata++;switch(timdata){case 0x01:sec=1;break;case 0x02:sec=0;min=1;break;case 0x03:min=0;hour=1;break;case 0x04:timdata=0;hour=0;TR0=1;break;default:break;}}//*********************************************时钟设置函数【完】void ftion1(){if(TR0==0) TR0=1;sec=0;min=0;hour=0;dis_p=bellbuf;timdata=0;rtimdata++;switch(rtimdata){case 0x01:rmin=1;break;case 0x02:rmin=0;rhour=1;break;case 0x03:rtimdata=0;rhour=0;arm=1;dis_p=clockbuf;break;default:break;}}//*********************************************闹钟设置函数【完】void ftion3(){if(TR0==0) TR0=1;day=0;mon=0;year=0;dis_p=date;timdata=0;rtimdata=0;dtimdata++;switch(dtimdata){case 0x01:day=1;break;case 0x02:day=0;mon=1;break;case 0x03:mon=0;year=1;break;case 0x04:dtimdata=0;year=0;dis_p=clockbuf;break;default:break;}}//*************************************************日期修改函数【完】void minus(){if(sec==1){if(0==clockbuf[2]) clockbuf[2]=59;else clockbuf[2]--;}else if(min==1){if(0==clockbuf[1]) clockbuf[1]=59;else clockbuf[1]--;}else if(hour==1){if(or==0) //判断进制{if(0==clockbuf[0]) clockbuf[0]=23;else clockbuf[0]--;}if(or==1){if(1==clockbuf[0]) clockbuf[0]=12;else clockbuf[0]--;}}else if(rmin==1){if(bellbuf[1]==0) bellbuf[1]=59;else bellbuf[1]--;}else if(rhour==1){if(or==0){if(bellbuf[0]==0) bellbuf[0]=23;else bellbuf[0]--;}if(or==1){if(bellbuf[0]==1) bellbuf[0]=12;else bellbuf[0]--;}}else if(day==1){if(date[2]==1) date[2]=31;else date[2]--;}else if(mon==1){if(date[1]==1) date[1]=12;else date[1]--;}else if(year==1){if(date[0]==1) date[0]=99;else date[0]--;}}//*************************************减1修改功能函数【完】void cum(){if(sec==1){if(59==clockbuf[2]) clockbuf[2]=0;else clockbuf[2]++;}else if(min==1){if(59==clockbuf[1]) clockbuf[1]=0;else clockbuf[1]++;}else if(hour==1){if(or==0) //判断进制{if(23==clockbuf[0]) clockbuf[0]=0;else clockbuf[0]++;}if(or==1){if(12==clockbuf[0]) clockbuf[0]=1;else clockbuf[0]++;}}else if(rmin==1){if(bellbuf[1]==59) bellbuf[1]=0;else bellbuf[1]++;}else if(rhour==1){if(or==0){if(bellbuf[0]==23) bellbuf[0]=0;else bellbuf[0]++;}if(or==1){if(bellbuf[0]==12) bellbuf[0]=1;else bellbuf[0]++;}}else if(day==1){if(date[2]==31) date[2]=1;else date[2]++;}else if(mon==1){if(date[1]==12) date[1]=1;else date[1]++;}else if(year==1){if(date[0]==99) date[0]=0;else date[0]++;}}//*************************************加1修改功能函数【完】void jinzhi(){if(or==0) or=1;else or=0;}//***********************************进制修改控制函数【完】void riqi(){if(ri==0){dis_p=date;}if(ri==1){dis_p=clockbuf;}ri++;if(ri==2) ri=0;}//********************************日期控显示函数【完】void stopwatch(){if(mb==0){dis_p=stop;mb=1;}else{mb=0;dis_p=clockbuf;}}//************秒表**********秒表**********秒表函数【完】void clock() interrupt 1{EA=0;if(msec1!=0x14) msec1++; //6MHz晶振定时10mselse{msec1=0;if(msec2!=100) msec2++; //定时1selse{if(rtim==1) count++; //闹钟启动标志计时10smsec2=0;if(clockbuf[2]!=59) clockbuf[2]++;else{clockbuf[2]=0;if(clockbuf[1]!=59) clockbuf[1]++;else{clockbuf[1]=0;if(or==0){if(clockbuf[0]!=23) clockbuf[0]++;else{clockbuf[0]=0;if((date[1]==1)||(date[1]==1)||(date[1]==1)||(date[1]==3)||(date[ 1]==5)||(date[1]==7)||(date[1]==8)||(date[1]==10)||(date[1]==12)){if(date[2]!=30) date[2]++;else{date[2]=1;if(date[1]!=11) date[1]++;else{date[1]=1;date[0]++;}}}if((date[1]==4)||(date[1]==6)||(date[1]==9)||(date[1]==11)){if(date[2]!=29) date[2]++;else{date[2]=1;if(date[1]!=11) date[1]++;else{date[1]=1;date[0]++;}}}if(date[1]==2){if((((date[0]%4==0)&&(date[0]%100!=0))||(date[0]%400==0))){if(date[2]!=28) date[2]++;else{date[2]=1;if(date[1]!=11) date[1]++;else{date[1]=1;date[0]++;}}}else{if(date[2]!=27) date[2]++;else{date[2]=1;if(date[1]!=11) date[1]++;else{date[1]=1;date[0]++;}}}}}}if(or==1){if(clockbuf[0]!=12) clockbuf[0]++;else{clockbuf[0]=0;if((date[1]==1)||(date[1]==1)||(date[1]==1)||(date[1]==3)||(date[ 1]==5)||(date[1]==7)||(date[1]==8)||(date[1]==10)||(date[1]==12)){if(date[2]!=30) date[2]++;else{date[2]=1;if(date[1]!=11) date[1]++;else{date[1]=1;date[0]++;}}}if((date[1]==4)||(date[1]==6)||(date[1]==9)||(date[1]==11)){if(date[2]!=29) date[2]++;else{date[2]=1;if(date[1]!=11) date[1]++;else{date[1]=1;date[0]++;}}}if(date[1]==2){if((((date[0]%4==0)&&(date[0]%100!=0))||(date[0]%400==0))){if(date[2]!=28) date[2]++;else{date[2]=1;if(date[1]!=11) date[1]++;else{date[1]=1;date[0]++;}}}else{if(date[2]!=27) date[2]++;else{date[2]=1;if(date[1]!=11) date[1]++;else{date[1]=1;date[0]++;}}}}}}}}}}EA=1;}//*******************************定时器0中断函数【完】void miaobiao() interrupt 3{TH1=(65536-10000)/256;TL1=(65536-10000)%256;if(stop[2]!=99) stop[2]++;else{stop[2]=0;if(stop[1]!=59) stop[1]++;else{stop[1]=0;if(stop[0]!=59) stop[0]++;else stop[0]=0;}}}//***********************************定时器1中断函数【完】。

数字钟汇编程序

数字钟汇编程序
CLR IE1
MOV NUM,#8
RETI
/*********************设置闹钟**********************/
SET_ALARM:
MOV A,ALARM_X
CJNE A,#1,SET_ALARM_BACK
SET_ALARM1:
ORG 0013H
LJMP SERVE_ALARM
ORG 0020H
MAIN:
MOV TMOD,#11H
MOV NUM_D1,#20
MOV SEC,#59 ;时间初始化
MOV MIN,#59
MOV HOU,#12
MOV NUM,#0
MOV NUM_KEY,#0
MOV ALARM_2_SEC,#00 ;闹钟2
MOV ALARM_2_MIN,#58
MOV ALARM_2_HOU,#12
MOV ALARM_3_SEC,#00 ;闹钟3
MOV ALARM_3_MIN,#05
MOV ALARM_3_HOU,#13
MOV ALARM_4_SEC,#00 ;闹钟4
CPL P1.0
RETURN4:
RETI
/******************外部中断0重置秒分时位置选择************/
ORG 0200H
SERVE_PLACE:
MOV MODE,#0 ;标记为外部中断0
LCALL DELAY
LCALL DELAY
MOV SECX,40H
MOV MINX,41H
MOV HOUX,42H
LCALL CHECK_KEY14

数字时钟_89C52_单片机C语言程序

数字时钟_89C52_单片机C语言程序
/*列扫描控制 LED1位 2位 3位 4位 5位 6位 7位 8位*/
uchar MON[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
uchar A;
uchar BIN=0; /* 【BIN】作为倒计时开始的标志 */
TH0 = (65536 - 10000) / 256; /*给定计时器高位赋予 初值=15536/256*/
TL0 = (65536 - 10000) % 256; /*给定计时器低位赋予 初值=15536%256 */
ET0 = 1; /*打开定时器外部终断0允许 ET1是中断器1的开关*/
P2 = C[4];
Delay(1);
P0 = Code[Msec%10]; /*第五位的数字显示【分】的【个】位 */
P2 = C[5];
Delay(1);
Delay(1);
P0 = 0x40; /*第六位符号【-】的显示 */
P2 = C[6];
Delay(1);
P2 = C[2];
Delay(1);
if(x/50==0)
P0 = 0x40; /*第三位符号【-】的显示 */
else
P0 = 0x00;
P2 = C[3];
Delay(1);
P0 = Code[min/10]; /*第四位的数字的显示【分】的【十】位 */
uchar month=7;
uchar month2;
uchar day=19;
uchar set1 = 1; /* set1=1 是调节 时分秒 set1=2时时调节 年月日 set=3时事调节闹钟 */

数字时钟设计(含完整程序)

数字时钟设计(含完整程序)

电子时钟设计一、实验目的学习8051定时器时间计时处理、按键扫描及LED数码管显示的设计方法。

二、设计任务及要求利用实验平台上4个LED数码管,设计带有闹铃功能的数字时钟,要求:1.在4位数码管上显示当前时间,显示格式为“时时分分” ;2.由LED闪动做秒显示;3.利用按键可对时间及闹玲进行设置,并可显示闹玲时间。

当闹玲时间到蜂鸣器发出声响,按停止键使可使闹玲声停止。

三、工作原理及设计思路利用单片机定时器完成计时功能,定时器0计时中断程序每隔5ms中断一次并当作一个计数,每中断一次计数加1,当计数200次时,则表示1s到了,秒变量加1,同理再判断是否1min钟到了,再判断是否1h到了。

为了将时间在LED数码管上显示,可采用静态显示法和动态显示法,由于静态显示法需要数据锁存器等较多硬件,可采用动态显示法实现LED显示。

闹铃声由交流蜂鸣器产生,电路如右图,当P1.7输出不同频率的方波,蜂鸣器便会发出不同的声音。

四、硬件电路设计及描述由于扩展了外部存储器,P0口只能作地址/数据总线,P2口只能作地址总线高8位,P3.7、P3.6作为外部数据存储器读写信号。

P3.0、P3.1作为串行输入、输出接口,在仿真模式下完成与PC机的通信,故也不可用。

实验仪上单片机可用作I/O的口仅有:P1.0--P1.7 ,8位;P3.2、P3.3、P3.4、P3.5 ,4位。

其中:P1.0 用作数据线SDA,P1.1用作时钟信号CLK,所以P1.0和P1.1应该接对应跳线的A 位,即跳线的中间和下面相连。

P1.3、P1.4、P1.5和P1.6是四个数码管的位扫描线,其中P1.6对应数码管W1,显示小时高位;P1.5对应数码管W2,显示小时低位;P1.4对应数码管W3,显示分钟高位;P1.3对应数码管W4,显示分钟低位。

P1.7连接蜂鸣器电路,输出不同频率的方波,使其发出不同的声音。

P1.2 用来控制秒的闪烁显示。

故,P1.2也应该接对应跳线的A 位。

数字钟程序

数字钟程序

ZWMADDR EQU 8002HZXMADDR EQU 8004HORG 0000HSJMP MAINORG 000BHAJMP T0SUBORG 0030HMAIN: MOV SP,#60H ;设置栈底MOV A,#00HMOV 70H,AMOV 71H,AMOV 72H,A;时钟计时缓冲区清0MOV R0,#7AHMOV R2,#06H;6LOOP: MOV @R0,AINC R0DJNZ R2,LOOP;从7AH-7FH显示缓冲区清0MOV TMOD,#01H ;定时计数器工作方式为方式1MOV TH0,#3CHMOV TL0,#0B0H ;装初值,定时50msSETB TR0;启动定时计数器SETB ET0;开中断SETB EAMOV R7,#14H;与定时50ms联合实现定时1SLOOP10:ACALL DISPJNB P1.0,LOOP10;p1.0为0,继续走时;p1.0为1,下一步将关掉中断停止走时进行设置时间CLR EAJB P1.1,HINCJB P1.2,MINCJB P1.3,SINCSETB EASJMP LOOP10HINC: ACALL DELAYJB P1.1, LL1AJMP LOOP10LL1: MOV A,72H;ADD A,#01HDA AMOV 72H,ACJNE A,#24H,LL2MOV 72H,#00HLL2: JNB P1.1, NEX11ACALL DISPSJMP LL2NEX11: SETB EAAJMP LOOP10MINC: ACALL DELAYJB P1.2, LL3AJMP LOOP10LL3: MOV A, 71HADD A,#01HDA AMOV 71H,ACJNE A,#60H,LL4MOV 71H,#00HLL4: JNB P1.2, NEX12ACALL DISPSJMP LL4NEX12: SETB EAAJMP LOOP10SINC: ACALL DELAYJB P1.3, LL5AJMP LOOP10LL5: MOV A, 70HADD A,#01HDA AMOV 70H, ACJNE A,#60H,LL6MOV 70H,#00HLL6: JNB P1.3, NEX13ACALL DISPSJMP LL6NEX13: SETB EAAJMP LOOP10ORG 0100HDELAY:MOV R5,#01HL1: MOV R6,#0FFHL2: DJNZ R6,L2DJNZ R5,L1RETORG 0120HT0SUB:MOV TL0,#0B0HMOV TH0,#3CH;重装定时计数器初值PUSH ACCPUSH PSWPUSH 00H;保护现场DJNZ R7,DONEMOV R7,#0AHJB P1.0, DONEMOV R0,#70HMOV A,@R0ADD A,#01HDA ACJNE A,#60H,NEXT1;不等于60时,将A的值给70HMOV @R0,#00H;等于60时将70H清0SJMP NEXT2NEXT1: MOV @R0,ASJMP DONENEXT2: INC R0MOV A,@R0ADD A,#01HDA ACJNE A,#60H,NEXT3MOV @R0,#00HSJMP NEXT4NEXT3: MOV @R0,ASJMP DONENEXT4: INC R0MOV A,@R0ADD A,#01HDA ACJNE A,#24H,NEXT5;不等于24时,将A的值给72HMOV @R0,#00H;等于24时,将72H清0SJMP DONE;设置好后退出,恢复断点现场NEXT5: MOV @R0,ADONE: POP 00HPOP PSWPOP ACC;恢复断点现场RETIORG 0200HDISP: MOV R0,#70H;R0指向时钟计数缓冲区第一个单元MOV R1,#7AH;R1指向7AH显示缓冲区MOV R2,#03H ;设置循环次数LOOP1: MOV A,@R0ANL A,#0FHMOV @R1,AINC R1MOV A,@R0SWAP AANL A,#0FHMOV @R1,AINC R0INC R1DJNZ R2,LOOP1;循环3次,把70H/71H/72H三个单元各自的高低4位拆分送至7AH-7FHMOV R3,#01HMOV R0,#7AHLOOP2: MOV A,@R0CJNE R3,#04H,BUJIALJMP JIADIAN;控制分针显示区加点与否BUJIA: CJNE R3,#10H,BUJIADIANLJMP JIADIAN;控制时针显示区加点与否BUJIADIAN: MOV DPTR,#CHARMOVC A,@A+DPTRMOV DPTR,#ZXMADDRMOVX @DPTR,AMOV A,R3MOV DPTR,#ZWMADDRMOVX @DPTR,AACALL DELAYINC R0MOV A,R3RL AMOV R3,ACJNE A,#40H,LOOP2RETJIADIAN: MOV DPTR,#CHAR1MOVC A,@A+DPTRMOV DPTR,#ZXMADDRMOVX @DPTR,AMOV A,R3MOV DPTR,#ZWMADDRMOVX @DPTR,AACALL DELAYINC R0MOV A,R3RL AMOV R3,ACJNE A,#40H,LOOP2RETCHAR: DB 3FH,06H,5BH,4FH,66H;没有点的字型码表DB 6DH,7DH,07H,7FH,6FHCHAR1: DB 0BFH,86H,0DBH,0CFH,0E6H ;有点的字型码表DB 0EDH,0FDH,87H,0FFH,0EFHEND。

数字时钟代码

数字时钟代码

数字时钟代码1. 介绍数字时钟是一种常见的显示时间的装置,它通过数字显示屏显示当前的小时和分钟。

本文档将介绍如何编写一个简单的数字时钟代码。

2. 代码实现以下是一个基本的数字时钟代码实现示例:import timewhile True:current_time = time.localtime()hour = str(current_time.tm_hour).zfill(2)minute = str(current_time.tm_min).zfill(2)second = str(current_time.tm_sec).zfill(2)clock_display = f"{hour}:{minute}:{second}"print(clock_display, end="\r")time.sleep(1)代码说明:- `time.localtime()` 函数返回当前时间的结构化对象,包括小时、分钟和秒等信息。

- `str(current_time.tm_hour).zfill(2)` 将小时转换为字符串,并使用 `zfill()` 方法填充到两位数。

- `str(current_time.tm_min).zfill(2)` 和`str(current_time.tm_sec).zfill(2)` 同理处理分钟和秒。

- 使用 f-string 格式化字符串 `clock_display`,将小时、分钟和秒显示为 `` 的形式。

- `print(clock_display, end="\r")` 使用 `\r` 实现覆盖打印,使得时钟在同一行连续显示。

- `time.sleep(1)` 让程序每隔一秒更新一次时间。

请注意,上述代码需要在支持 Python 的环境中运行。

3. 结束语通过以上的代码实现,我们可以编写一个简单的数字时钟。

带闹钟功能的数字时钟程序

带闹钟功能的数字时钟程序

#include<reg52.h>#include<intrins.h>#define uint unsigned int#define uchar unsigned charsbit lcdrs=P1^0;sbit lcdrw=P1^6;sbit lcden=P1^1 ;sbit k1set=P2^0;//控制模式选择sbit k2up=P2^1;//加操作sbit k3down=P2^2;//减操作sbit T_RST=P1^2;sbit T_IO=P1^3;sbit T_CLK=P1^4;sbit ACC0=ACC^0;sbit ACC7=ACC^7;uint t1;sbit did=P3^5;uchar clocks,clockf,clockm,year,week,weeks,day,month,b,sw,gw,t,years,months,days;//b就是keyflag按键标志位uchar hour,mie,sei,c,nhour,nmie,shour,smie,clockms,i;uint keyflag;//按键标志位/*********延时函数****************/void delay(uint z){uint x,y;for(x=0;x<114;x++)for(y=0;y<z;y++);}/********ds1320控制***************/void write_byte(uchar da)//上升沿,写入操作{uchar i;ACC=da;for(i=8;i>0;i--){T_IO=ACC0;T_CLK=1;T_CLK=0;ACC>>=1;}}uchar read_byte(void)//下降沿,读操作{uchar i;for(i=8;i>0;i--){ACC>>=1;ACC7=T_IO;T_CLK=1;T_CLK=0;}return(ACC);}void write_1302(uchar addr,uchar da) //写数据,先送地址,在写数据{T_RST=0;//停止工作T_CLK=0;T_RST=1;//重新工作write_byte(addr);//写地址write_byte(da);//写入数据T_CLK=1;T_RST=0;}uchar read_1302(uchar addr)//读数据,先送地址再读数据{uchar temp,tempsw,tempgw,temp10;T_RST=0;T_CLK=0;T_RST=1;write_byte(addr);//写入地址temp=read_byte();T_CLK=1;T_RST=0;//停止工作tempsw=temp/16;tempgw=temp%16;temp10=10*tempsw+tempgw;return(temp10);//temp是16进制的}void Initial(void){write_1302(0x8e,0x00); //禁止写保护write_1302(0x80,0x00); //秒位初始化write_1302(0x82,0x06); //分钟初始化write_1302(0x84,0x22); //时位初始化write_1302(0x86,0x05); //写日write_1302(0x88,0x05); //写月write_1302(0x8a,0x06); //写星期write_1302(0x8c,0x12); //写年write_1302(0x8e,0x80); //允许写保护}/********1602显示***************/void write_cmd(char cmd){lcdrs=0;P0=cmd;delay(1);lcden=1;delay(1);lcden=0;}void write_data(uchar dat){lcdrs=1;P0=dat ;delay(1);lcden=1;delay(1);lcden=0;}void write_str(uchar *str){while(*str!='\0'){write_data(*str++);delay(5);}}/*********响铃***********************/void fn(){did=0;while(did==0){if(k2up==0)did=1;}while(did==1){if(k3down==0)did=0;}did=1;delay(120);}/*************初始化*********************/void init(){b=0; t=0; nhour=7;nmie=0;keyflag=0;////初始化1602lcdrw=0;lcden=0;write_cmd(0x38);write_cmd(0x0c);write_cmd(0x06);write_cmd(0x01);write_cmd(0x80);b=0;//Initial() ;}/********显示函数*******************/void display(uchar tt){write_data(tt/10+48);write_data(tt%10+48);}/**************按键函数********************/void keyscan(){ucharclocks1,clocks2,clockf1,clockf2,year1,year2,month1,month2,day1,day2,clockm1,clockm2,week1;if(k1set==0){delay(10);if(k1set==0){did=0;delay(10);did=1;b++;}while(!k1set);write_cmd(0xcf);write_str("M");if(b==1){years=year;months=month;days=day;weeks=week;hour=clocks;mie=clockf;clockms=clockm;write_cmd(0x80);write_str("DA TE:20");write_data(years/10+48);write_data(years%10+48);write_str("/");write_data(months/10+48);write_data(months%10+48);write_str("/");write_data(days/10+48);write_data(days%10+48); write_cmd(0x87);write_cmd(0x0f);//开显示光标}if(b==2){write_cmd(0x8a);}if(b==3){write_cmd(0x8d);}if(b==4){write_cmd(0xc5);}if(b==5){write_cmd(0xc8);}if(b==6){write_cmd(0xce);}if(b==7){write_cmd(0xc0);write_str("ALAM");write_cmd(0xc5);display(nhour);write_str(":");display(nmie);write_str("--W AKE");write_cmd(0xc5);}if(b==8){write_cmd(0xc8);display(nmie);write_str("--W AKE");write_cmd(0xc8);}if(b==9){write_cmd(0x01);write_cmd(0x0c);// write_str("TIME ");b=0;clocks1=hour/10; ///十进制转换十六进制clocks2=hour%10;clocks1=clocks1&0xff;clocks2=clocks2&0xff;clocks1<<=4;clocks1=clocks1|clocks2;clockm1=clockms/10;clockm2=clockms%10;clockm1=clockm1&0xff;clockm2=clockm2&0xff;clockm1<<=4;clockm1=clockm1|clockm2;clockf1=mie/10;clockf2=mie%10;clockf1=clockf1&0xff;clockf2=clockf2&0xff;clockf1<<=4;clockf1=clockf1|clockf2;day1=days/10; ///十进制转换十六进制day2=days%10;day1=day1&0xff;day2=day2&0xff;day1<<=4;day1=day1|day2;month1=months/10; ///十进制转换十六进制month2=months%10;month1=month1&0xff;month2=month2&0xff;month1<<=4;month1=month1|month2;year1=years/10; ///十进制转换十六进制year2=years%10;year1=year1&0xff;year2=year2&0xff;year1<<=4;year1=year1|year2;week1=weeks%10;write_1302(0x8e,0x00);//wp=0,写操作write_1302(0x80,0x00);//写秒write_1302(0x82,clockf1);//写分write_1302(0x84,clocks1);//写时write_1302(0x86,day1); // 写日write_1302(0x88,month1);//写月write_1302(0x8a,week1); //写星期write_1302(0x8c,year1); //写年write_1302(0x8e,0x80);//WP=1,写保护}}if(b!=0){if(k2up==0){delay(5);if(k2up==0){did=0;delay(10);did=1;delay(10);while(!k2up);if(b==1){years++;if(years>=99)years=1;write_cmd(0x87);display(years);write_cmd(0x87);}if(b==2){months++;if(months>=12)months=1;write_cmd(0x8a);display(months);write_cmd(0x8a);}if(b==3){days++;if(days>=32)days=1;write_cmd(0x8d);display(days);write_cmd(0x8d);}if(b==4){hour++;if(hour>=24)hour=0;write_cmd(0xc5);display(hour);write_cmd(0xc5);}if(b==5){mie++;if(mie>=60)mie=0;write_cmd(0xc8);display(mie);write_cmd(0xc8);}if(b==6){weeks++;if(weeks>7)weeks=1;write_cmd(0xce);write_data(weeks%10+48);write_cmd(0xce);}if(b==7){nhour++;if(nhour>=24)nhour=0;write_cmd(0xc5);display(nhour);write_cmd(0xc5);}if(b==8){nmie++;if(nmie>=60)nmie=0;write_cmd(0xc8);display(nmie);write_cmd(0xc8);}}}if(k3down==0){ delay(10);if(k3down==0){did=0;delay(10);did=1;delay(10);while(!k3down);if(b==1){years=years-1;if(years==-1)years=99;write_cmd(0x87);display(years);write_cmd(0x87);}if(b==2){months--;if(months<=0)months=12;write_cmd(0x8a);display(months);write_cmd(0x8a);}if(b==3){days--;if(days==0)days=31;write_cmd(0x8d);display(days);write_cmd(0x8d);}if(b==4){hour=hour-1;if(hour==-1)hour=23;write_cmd(0xc5);display(hour);write_cmd(0xc5);}if(b==5){mie=mie-1;if(mie==-1)mie=59;write_cmd(0xc8);display(mie);write_cmd(0xc8);}if(b==6){weeks=weeks-1;if(weeks==0)weeks=7;write_cmd(0xce);write_data(weeks%10+48);write_cmd(0xce);}if(b==7){nhour=nhour-1;if(nhour==-1)nhour=23;write_cmd(0xc5);display(nhour);write_cmd(0xc5);}if(b==8){nmie=nmie-1;if(nmie==-1)nmie=59;write_cmd(0xc8);display(nmie);write_cmd(0xc8);}}}}}/***************主函数*****************************/ void main(){init();while(1){keyscan();if(b==0){clockf=read_1302(0x83);clocks=read_1302(0x85);clockm=read_1302(0x81);year=read_1302(0x8d);month=read_1302(0x89);day=read_1302(0x87);week=read_1302(0x8b);write_cmd(0x80);write_str("DA TE:20");write_data(year/10+48);write_data(year%10+48);write_str("/");write_data(month/10+48);write_data(month%10+48);write_str("/");write_data(day/10+48);write_data(day%10+48);write_cmd(0xc0);write_str("TIME:");display(clocks);write_str(":");display(clockf);write_str(":");display(clockm);write_str("-");write_data(week%10+48);for(i=0;i<=24;i=i+2){ if((clocks==nhour+i)&&(clockf==nmie)) fn();//while(did==0){if(k2up==0)did=1;}//while(did==1){if(k3down==0)did=0;} }}}}。

数字钟程序

数字钟程序

#include<reg52.h>code senen_seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共阴0-9编码bitkey1_enter=0,key2_enter=0,key3_enter=0,key4_enter=0,countdown_mark=0,stopwatch_mark=0 ,count_mark=0,bell_mark=0,sm=0,ringf=0;//状态标志unsigned char program=0,program_variable=0,count_bit=0,count=0;unsigned char hour=0,minute=59,second=0;//时钟变量sbit P3_0=P3^0; //位码&键盘定义sbit P3_1=P3^1;sbit P3_2=P3^2;sbit P3_3=P3^3;sbit P3_4=P3^4;sbit P3_5=P3^5;sbit P3_6=P3^6;sbit P3_7=P3^7;sbit p15= P1^5;sbit p14= P1^4;sbit p13= P1^3;sbit p12= P1^2;sbit p11= P1^1;//他变我也变?unsigned char delayed_hour=1,delayed_minute=0,delayed_second=1; //闹钟变量unsigned char count_hour=0,count_minute=0,count_second=0;//计时计数变量unsigned intcount_time=0,count_count=0,kd1,kd2,kd3,kd4,i; // count_time更新时钟,count_count倒计时中断次数,为下一单位void delay(unsigned int t) //延时子程序延时10t us 晶振12.0Mhz{unsignedinti,j;for(i=0;i<t;i++)for(j=0;j<10;j++);}void time0_init(void){ //定时计数0器初始化EA=0; //中断开放位TR0=0; //T0计数否TMOD=0x01;//工作方式1TH0=0xec; //装入初值0xec73 计数5004TL0=0x73;ET0=1;TR0=1;EA=1;}static void timer0_isr(void) interrupt 1 //定时计数0器中断函数中断号定对应地址?需加入防干扰?时钟何种模式都更新{TR0=0;TH0=0xec; //重新装入初值TL0=0x73;TR0=1;count_time++; //时钟计时程序if(count_time>=199){count_time=0; //199换一秒second++;if(second>=60){second=0;minute++;if(minute>=60){minute=0;hour++;if(hour>=24)hour=0;}}} //时间更新if(delayed_hour==hour &&delayed_minute==minute &&delayed_second<4 &&ringf==1) //时钟设定时间到则蜂鸣器响三秒second<4即second<=3,中断中就响了这里可以改频率?{if(count_time*81%2==1)p13=0;elsep13=1;}if(minute==59){if(second==50|| second==52|| second==54|| second==56|| second==58){if(count_time*81%2==1)p13=0;elsep13=1;}}// If(minute==59)if(minute==0 &&second==0){for(i=0;i<10;i++)if(i%2==0)p13=0;elsep13=1;//整点报时功能代码组}if(countdown_mark==1){count_count++;if(count_count>=199 && (count_second!=0|count_minute!=0|count_hour!=0)) {count_count=0;count_second--;if(count_second>=60){count_second=59;count_minute--;if(count_minute>=60){count_minute=59;count_hour--;if(count_hour>=100) //只能显示100以内之数count_hour=99;}}} //倒计时程序//if(count_second==0&&count_minute==0&&count_hour==0&&count_count<=12000) //p13=0;//else p13=1;//倒计时到也响铃if(count_count>=15000)count_count=14000;}// if(countdown_mark==1)if(stopwatch_mark==1){ //秒表程序count_count++;if(count_count>=2){count_count=0;count_second++;if(count_second>=100){count_second=0;count_minute++;if(count_minute>=60){count_minute=0;count_hour++;if(count_hour>=60)count_hour=0;}}}}}unsigned char show_key (void)//此不变program{unsigned char x=0,y=0;kd1=kd2=kd3=kd4=0;//switch (program) //送第一位数据{case 0: P0&=senen_seg[second%10]; //时钟秒的个位break;case 1: if(count_time>=90)P0&=senen_seg[second%10]; //校正秒的个位break;case 2: if(delayed_hour==24)P0=0xfe; //闹钟秒的个位else P0&=senen_seg[delayed_second%10];break;case 3: if(count_bit>=0)P0&=senen_seg[count_second%10]; //倒计时秒的个位else P0=0xff;break;case 4: P0&=senen_seg[count_second%10];//秒表秒的个位break;case 5: P0&=senen_seg[count_second%10];//计数器个位break;}P3_1=0;delay(3);if(p15==0){ //功能键1防干扰识别kd1=kd1+1;if(count<=254)count++;}if(p14==0)kd2=kd2+1; //功能键2防干扰识别if(p12==0)kd3=kd3+1; //功能键3防干扰识别if(p11==0)kd4=kd4+1; //功能键4防干扰识别delay(3);if(p15==0){ //功能键1防干扰识别kd1=kd1+1;if(count<=254)count++;}if(p14==0)kd2=kd2+1; //功能键2防干扰识别if(p12==0)kd3=kd3+1; //功能键3防干扰识别if(p11==0)kd4=kd4+1; //功能键4防干扰识别delay(4);if(p15==0){ //功能键1防干扰识别kd1++;if(count<=254)//长短按键之识别count++;}if(p14==0)kd2++; //功能键2防干扰识别if(p12==0)kd3++; //功能键3防干扰识别if(p11==0)kd4=kd4+1; //功能键4防干扰识别if(p15==0&&kd1>=kd2&&kd1>=kd3&&kd1>=kd4){ //功能键1识别key1_enter=1;if(count<=254)count++;}if(p14==0&&kd2>=kd1&&kd2>=kd3&&kd2>=kd4)key2_enter=1; //功能键2识别if(p12==0&&kd3>=kd2&&kd3>=kd1&&kd3>=kd4)key3_enter=1; //功能键3识别if(p11==0&&kd4>kd1&& kd4>kd2&&kd4>kd3)key4_enter=1;P3_1=1;P0|=0xff;switch (program) //送第二位数据{case 0: P0&=senen_seg[second/10]; //时钟秒的十位break;case 1: if(count_time>=90) P0&=senen_seg[second/10]; //校正秒的十位break;case 2: if(delayed_hour==24) P0=0xfe; //闹钟秒的十位else P0&=senen_seg[delayed_second/10];break;case 3: if(count_bit>=1) P0&=senen_seg[count_second/10]; //倒计时秒的十位else P0=0xff;break;case 4: P0&=senen_seg[count_second/10];//秒表秒的十位break;case 5: P0&=senen_seg[count_second/10];//计数器十位break;}P3_2=0;delay(10);P3_2=1;P0|=0xff;switch (program) //送第三位数据{case 0: P0&=senen_seg[minute%10]; //时钟分的个位break;case 1: if(count_time>=90)P0&=senen_seg[minute%10]; //校正分的个位break;case 2: if(delayed_hour==24)P0=0xfe; //闹钟分的个位else P0&=senen_seg[delayed_minute%10];break;case 3: if(count_bit>=2)P0&=senen_seg[count_minute%10]; //倒计时分的个位else P0=0xff;break;case 4: P0&=senen_seg[count_minute%10];//秒表分的个位break;case 5: P0&=senen_seg[count_minute%10];//计数器百位break;}P3_3=0;delay(10);P3_3=1;P0|=0xff;switch (program) //送第四位数据{case 0: P0&=senen_seg[minute/10]; //时钟秒的个位break;case 1: if(count_time>=90) P0&=senen_seg[minute/10]; //校正秒的个位break;case 2: if(delayed_hour==24) P0=0xfe; //闹钟秒的个位else P0&=senen_seg[delayed_minute/10];break;case 3: if(count_bit>=3) P0&=senen_seg[count_minute/10];//倒计时秒的个位else P0=0xff;break;case 4: P0&=senen_seg[count_minute/10];//秒表秒的个位break;case 5: P0&=senen_seg[count_minute/10];//计数器千位break;}P3_4=0;delay(10);P3_4=1;P0|=0xff;switch (program) //送第五位数据{case 0: if(sm==0||hour<=12)P0&=senen_seg[hour%10]; //时钟时的个位else P0&=senen_seg[(hour-12)%10];break;case 1: if(count_time>=90){if(sm==0||hour<=12)P0&=senen_seg[hour%10]; //校正时的个位else P0&=senen_seg[(hour-12)%10];}break;case 2: if(delayed_hour==24)P0=0xfe; //闹钟时的个位else P0&=senen_seg[delayed_hour%10];break;case 3: if(count_bit>=4)P0&=senen_seg[count_hour%10]; //倒计时时的个位else P0=0xff;break;case 4: P0&=senen_seg[count_hour%10]; //秒表时的个位break;case 5: P0&=senen_seg[count_hour%10]; //计数器万位break;}P3_5=0;delay(10);if(p14==1 && key2_enter==1){x=3; //确认功能键2识别,返回3key2_enter=0;}P3_5=1;P0|=0xff;switch (program) //送第六位数据{case 0: if(sm==0||hour<=12)P0&=senen_seg[hour/10];//时钟时的十位else P0&=senen_seg[(hour-12)/10];break;case 1: if(count_time>=90){ if(sm==0||hour<12)P0&=senen_seg[hour/10]; //校正时的十位else P0&=senen_seg[(hour-12)/10];}break;case 2: if(delayed_hour==24)P0=0xfe; //闹钟时的个位else P0&=senen_seg[delayed_hour/10];break;case 3: if(count_bit>=5)P0&=senen_seg[count_hour/10]; //倒计时时的个位else P0=0xff;break;case 4: P0&=senen_seg[count_hour/10];//秒表时的个位break;case 5: P0&=senen_seg[count_hour/10];//计数器万位break;}P3_6=0;delay(10);if(p15==1 && key1_enter==1){ //确认功能键1识别,执行退出或进入下一个功能if(count>=170) x=1; //确认功能键1为长按,返回1else x=2; //确认功能键1为短按,返回2key1_enter=0;count=0;}if(p12==1&&key3_enter==1){x=4; //确认功能键3识别,返回4key3_enter=0;}if(p11==0&&key4_enter==1){if(sm==0)sm=1;elsesm=0;}P3_6=1;P0|=0xff;if(program<=1 &&count_time>=100)P0&=0xff; //校时和显示功能时钟时冒号闪烁if(program<=1 &&count_time<=100)P0&=0x7f;if(program==2) P0&=0x7f; //设置闹钟功能时冒号长亮if(program==3) P0&=0xff; //设置倒计时功能时冒号长灭if(program==4) P0&=0x7f; //设置秒表功能时冒号长亮if(program==5) P0&=0xff; //设置计数时冒号长灭y=x;x=0;return y;}void main()//各种标识符在这里实现定义{ //主程序P0=0xff;P3=0xff;time0_init(); //初始化while(1){switch(program){case 0: while(program==0)//多余{ //时钟菜单switch(show_key()){case 0: break;case 1: program=0;break;case 2: program=1;break;case 3: ringf=0;break;}}break; //校时菜单case 1: while(program==1){switch(show_key()){case 0: break;case 1: program=0;break;case 2: program=2;break;case 3: hour++;if(hour>=24)hour=0;break;case 4: minute++;if(minute>=60)minute=0;break;}}break;case 2: while(program==2){ ringf=1; //闹钟菜单switch(show_key()){case 0: break;case 1: program=0;break;case 2: program=3;break;case 3: delayed_hour++;if(delayed_hour>=25)delayed_hour=0;break;case 4: delayed_minute++;if(delayed_minute>=60)delayed_minute=0;break;}}break;case 3: while(program==3){ //倒计时菜单switch(show_key()){case 0: break;case 1: program=0;break;case 2: program=4;break;case 3: count_bit++;if(count_bit>=7)count_bit=0;break;case 4: switch(count_bit){case 0: count_second+=1;break;case 1: count_second+=10;break;case 2: count_minute+=1;break;case 3: count_minute+=10;break;case 4: count_hour+=1;break;case 5: count_hour+=10;break;case 6: break;}if(count_hour>=100)count_hour-=100;if(count_minute>=60)count_minute-=60;if(count_second>=60)count_second-=60;break;}if(count_bit==6)countdown_mark=1;elsecountdown_mark=0;}break;case 4: count_hour=0; //秒表菜单count_minute=0;count_second=0;while(program==4){switch(show_key()){case 0: break;case 1: program=0;break;case 2: program=5;break;case 3: stopwatch_mark=~stopwatch_mark;break;case 4: if(stopwatch_mark==0){count_hour=0;count_minute=0;count_second=0;}break;}}break; //计数器菜单case 5: count_hour=0;count_minute=0;count_second=0;while(program==5){switch(show_key()){case 0: break;case 1: program=0;break;case 2: program=0;break;case 3: count_second++;if(count_second>=100){count_second=0;count_minute++;if(count_minute>=100){count_minute=0;count_hour++;if(count_hour>=100)count_hour=0;}}break;case 4: count_hour=0;count_minute=0;count_second=0;break;}if(p13==0){while(p13==0)show_key();count_second++;if(count_second>=100){count_second=0;count_minute++;if(count_minute>=100){count_minute=0;count_hour++;if(count_hour>=100)count_hour=0;}}}}break;}if(program!=3)countdown_mark=0;if(program!=4)stopwatch_mark=0;}}。

数字钟程序

数字钟程序
P1=scanValue; /*发扫描值*/
scanTempUchar=P1; /*读入扫描值*/
scanTempUchar=scanTempUchar&0xf0;
if(scanTempUchar!=0xf0)
{
{
switch(scanTempUchar)
{
case 0x70: return 0x0c; break;
case 0xb0: return 0x0d; break;
case 0xd0: return 0x0e; break;
case 0xe0: return 0x0f; break;
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
static const char code c_keyCode[16]=
{ 0x00,0x01,0x02,0x03,0x04, /*键盘1,2,3,4*/
switch(scanTempUchar)
{
case 0x70: return 0x00;break;
case 0xb0: return 0x01;break;
case 0xd0: return 0x02;break;
case 0xe0: return 0x03;break;
case 0xb0: return 0x09;break;
case 0xd0: return 0x0a;break;
case 0xe0: return 0x0b;break;
default:return 0x55;break;
} }
scanValue=0xf7;//第四行
default:return 0x55; break;

数字时钟c程序

数字时钟c程序

#include < reg52.h >//#include < intrins.h >#define uchar unsigned char#define uint unsigned intsbit dula=P2^6;sbit wela=P2^7;sbit rs=P3^5;sbit lcden=P3^4;sbit s1=P1^0;//功能键sbit s2=P1^1;//增加键sbit s3=P1^2;//减小键sbit s4=P1^3;//闹钟查看键sbit rd=P3^7;sbit beep=P2^3;//蜂鸣器sbit dscs=P1^4;sbit dsas=P1^5;sbit dsrw=P1^6;sbit dsds=P1^7;sbit dsirq=P3^3;bit flag1,flag_ri;//定义两个位变量uchar s1num,flag;//其它变量定义char miao,shi,fen,year,month,day,week,amiao,afen,ashi; uchar code table[]=" 20 - - ";//液晶固定显示内容uchar code table1[]=" : : ";void write_ds(uchar,uchar);//函数申明void set_alarm(uchar,uchar,uchar);void read_alarm(); uchar read_ds(uchar);void set_time();sbit DQ = P2^2 ; //定义DS18B20端口DQ//sbit BEEP=P2^4 ; //蜂鸣器驱动线bit presence ;//sbit LCD_RS = P3^5 ;//sbit LCD_RW = P2^0 ;//sbit LCD_EN = P3^4 ;/* uchar code cdis1[ ] = {" DS18B20 OK "} ;*/ uchar code cdis2[ ] = {" . C "} ;//uchar code cdis3[ ] = {" DS18B20 ERR0R "} ;//uchar code cdis4[ ] = {" PLEASE CHECK "} ;unsigned char data temp_data[2] = {0x00,0x00} ;unsigned char data display[5] = {0x00,0x00,0x00,0x00,0x00} ;unsigned char code ditab[16] = {0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09} ;//void beep() ;unsigned char code mytab[8] = {0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00} ;#define delayNOP() ; {_nop_() ;_nop_() ;_nop_() ;_nop_() ;} ;void write_com(uchar );void write_date(uchar );/*******************************************************************/ /*void delay1(int ms){unsigned char y ;while(ms--){for(y = 0 ; y<250 ; y++){_nop_() ;_nop_() ;_nop_() ;_nop_() ;}}}*//******************************************************************//*检查LCD忙状态*/ /*lcd_busy为1时,忙,等待。

多功能数字钟程序

多功能数字钟程序
}
}
}
else
{
if(mode==3)mode=0;else mode++;//模式选择
}
}
}break;
default :break;
}
}
//***************************************** //定时0中断****************************
void incsec() interrupt 1
case 43: {
if(loose==0)
{
loose=1;
if(set_clock==1||set_time==1)//进入设置状态
{
if(set_time==1)
{
switch(select)
{
case 1:{ if(month==1)month=12;else month--;}break;//月份设置
if(j==3687)
{
second++;//加1秒
P2_2=~P2_2; P2_3=~P2_3;//使led闪烁
j=0;i=0;
}
}
void beep() interrupt 3
{
uchar mi,rui,duo;
k++;
if(k<2000)//mi响约46ms,四分之一拍
//*******************************************************************************************
void Delay(void)//数码管显示延时
{
uint i;

数字时钟程序

数字时钟程序

LJMP STARTORG 000BHLJMP INIT0START: MOV R0,#70HMOV R7,#0CHLOOP: MOV @R0,#00HINC R0DJNZ R7,LOOP ;清零MOV 72H,#10 ;对连字符进行装值MOV 75H,#10MOV TMOD,#01H ;选择定时器/计数器T0,方式1MOV TL0,#0B0HMOV TH0,#03CH ; 定时50msSETB EASETB ET0SETB TR0MAIN: LCALL SCANLCALL KEYSCANSJMP MAIN;*数码管显示程序*SCAN: MOV A,78HMOV B,#0AHDIV AB ;时间秒的十位送给A,时间秒的个位送BMOV 71H,A ;时间秒要显示的十位MOV 70H,B ;时间秒要显示的个位MOV A,79HMOV B,#0AHDIV AB ;时间分的十位送给A,时间分的个位送BMOV 74H,A ;时间分要显示的十位送地址MOV 73H,B ;时间分要显示的个位送地址MOV A,7AHMOV B,#0AHDIV AB ;时间时的十位送给A,时间时的个位送BMOV 76H,BMOV 77H,A ;时间时要显示的个位送地址MOV R5,#7FHMOV R3,#09HSCAN1: MOV A,R5;数码管的显示程序MOV P2,AMOV A,@R1MOV DPTR,#TABMOVCA,@A+DPTR ;对字段表取值显示MOV P0,AMOV A,R5LCALL DL1MSINC R1MOV A,R5RL AMOV R5,ADJNZ R3,SCAN1MOV P2,#0FFHMOV P0,#0FFHRETTAB: DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0BFH ;"0~9"和"-"的字段表DL1MS: MOV R4,#250 ;延时1ms子程序DL1: NOPNOPDJNZ R4,DL1RETDL20MS: MOV R6,#20 ;延时20ms子程序DL2: MOV R7,#250DL3: NOPNOPDJNZ R7,DL3DJNZ R6,DL2RET;*按键程序***KEYSCAN: CLR EAJNB P1.0,KEYSCAN0 ;P1.0有按键按下则跳转到子程序KEYSCAN0JNB P1.1,KEYSCAN1 ;P1.1有按键按下则跳转到子程序KEYSCAN1 KEYOUT: SETB EARETKEYSCAN0:LCALL DL20MS ;20ms的延时消抖JB P1.0,KEYOUTWAIT0: JNB P1.0,W AIT0 ;判断按键是否松手,松手就往下执行程序INC 7CHMOV A,7CHCLR ET0CLR TR0CJNE A,#03H,KEYOUT ;按下第一次和第二次对分、时选定MOV 7CH,#00 ;按下第三次时就启动计时SETB ET0SETB TR0SJMP KEYOUTKEYSCAN1:LCALL DL20MS ;按键加一的程序JB P1.1,KEYOUTWAIT1: JNB P1.1,W AIT1MOV A,7CHCJNE A,#02H,KSCAN11 ;如果功能键按下则对时加一调整INC 7AHMOV A,7AHCJNE A,#18H,KEYOUT ;如果加到24则清零MOV 7AH,#00SJMP KEYOUTKSCAN11:INC 79H ;如果功能键是按下第二次则对分进行加一调整MOV A,79HCJNE A,#3CH,KEYOUT ;如果加到60则清零MOV 79H,#00SJMP KEYOUT;*中断程序*INIT0: PUSH ACCPUSH PSWSETB ET0MOV TL0,#0B0HMOV TH0,#03CHSETB TR0INC 7BHMOV A,7BHCJNE A,#14H,OUTT0;50ms是否到20次,没有到就继续执行50ms的延时MOV 7BH,#00INC 78HMOV A,78HCJNE A,#3CH,OUTT0 ;一秒的延时是否计到60次,没有就继续执行MOV 78H,#00INC 79HMOV A,79HCJNE A,#3CH,OUTT0 ;一分的延时是否计到60次,没有就继续执行MOV 79H,#00INC 7AHMOV A,7AHCJNE A,#18H,OUTT0 ;一小时的延时是否计到24次,没有就继续执行程序MOV 7AH,#00OUTT0: SETB ET0 ;启动定时器T0POP PSWPOP ACCRETIEND。

数字电子时钟程序与仿真

数字电子时钟程序与仿真

数字电子时钟程序【闹铃(持续5s),整点报时(几点报几下,每两下之间隔间2s,每声持续2s)】程序:#include<reg51.h>#include<absacc.h>#define uchar unsigned char#define uint unsigned int〃此表为LED的字模,共阴数码管0-9 -uchar code dispcode[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; 〃段码控制/*定义并初始化变量*/sbit key1=P3A0;sbit key2=P3A1;sbit key3=P3A2;sbit key4=P3A3;sbit buzz=P1A3;uchar mstcnt=0;〃定时器计数,定时50ms,mstcnt 满20,秒加 1uchar seconde1=0;uchar bjcs;uchar minite1=0;uchar hour1=7;uchar seconde2=0;uchar minite2=0;uchar hour2=8;uchar temp1=0;uchar temp2=0;uchar count1,flag,temp;/*函数声明*/void delay(uint z); //延时子程序void time_pro(); 〃时间处理子程序void display(uchar hour,uchar minite,uchar seconde);湿示子程序void keyscan( ); //键盘扫描子程序void zhengdian();void dinshi();void delay(uint z){uint x,y;for(x=0;x<z;x++) for(y=0;y<110;y++);void time_pro(void) /* 时间处理子程序*/(if(seconde1==60)(seconde1=0;minite1++;if(minite1==60)(minite1=0;hour1++;if(hour1==24)hour1=0;} _void display(uchar hour,uchar minite,uchar seconde) /* 显示子程序*/ ( uchar h1,h2,m1,m2,s1,s2;s2=seconde/10;s1=seconde%10;m2=minite/10;m1=minite%10;h2=hour/10;h1=hour%10;P2=0XFE; 〃1111 1110if(temp1==1) //功能选项,通过点提醒来调节相应位的时间P0=dispcode[s1]|0x80; //点提醒elseP0=dispcode[s1];//秒个位delay(1);P2=0XFD;//1111 1101P0=dispcode[s2];//秒十位delay(1);P2=0XFB; //1111 1011 P0=dispcode[10];〃间隔符- delay(1);P2=0XF7; 〃1111 0111 if(temp1==2)// P0=dispcode[m1]|0x80; elseP0=dispcode[m1];〃分个位delay(1);P2=0XEF; //1110 1111P0=dispcode[m2];//^+fe delay(1);P2=0XDF; 〃1101 1111P0=dispcode[10];〃间隔符- delay(1);P2=0XBF; //1011 1111 if(temp1==3)P0=dispcode[h1]|0x80;//时个位elseP0=dispcode[h1]; delay(1);P2=0X7F; //0111 1111P0=dispcode[h2];//时十位delay(1);void keyscan(void) /*键盘扫描子程序*/ (if(key1==0)(delay(10);if(key1==0)//TR0=0;temp1++;if(temp1==4){temp1=0;TR0=1;)while(!key1)switch(temp2){case 0:display(hour1,minite1,seconde1);break;case 1:display(hour2,minite2,seconde2);break;if(key2==0) {delay(10);if(key2==0)if(temp2==0) 〃闹钟选择键{//TR0=0; switch(templ){ case 1:seconde1++;if(seconde1==60)seconde1=0;break; case2:minite1++;if(minite1==60)minite1=0;break;case 3:hour1++;if(hour1==24)hour1=0;break; } while(!key2) display(hour1,minite1,seconde1);} if(temp2==1){ TR0=1;switch(temp1){ case 1:seconde2++;if(seconde2==60)seconde2=0;break; case2:minite2++;if(minite2==60)minite2=0;break;case 3:hour2++;if(hour2==24)hour2=0;break; } while(!key2) display(hour2,minite2,seconde2);}}}if(key3==0){delay(10);if(key3==0) {if(temp2==0){ //TR0=0;switch(temp1){ case 1:if(seconde1==0)seconde1=60;seconde1--;break; case2:if(minite1==0)minite1=60;minite1--;break;case 3:if(hour1==0)hour1=24;hour1--;break; } while(!key3)display(hour1,minite1,seconde1);} if(temp2==1){ TR0=1;switch(templ) {case 1:if(seconde2==0)seconde2=60;seconde2--;break; case2:if(minite2==0)minite2=60;minite2--;break; case3:if(hour2==0)hour2=24;hour2--;break;}while(!key3) display(hour2,minite2,seconde2);}}}if(key4==0){delay(10);if(key4==0) {temp1=0;temp2++;if(temp2==2) temp2=0; while(!key4) switch(temp2) {case 0:display(hour1,minite1,seconde1);break; case1:display(hour2,minite2,seconde2);break;}}}switch(temp2){case 0:display(hour1,minite1,seconde1);break; case1:display(hour2,minite2,seconde2);break;}} void dinshi() /*定时闹钟*/{uint i;if(hour1==hour2&&minite1==minite2&&(seconde1>=seconde2&&seconde1<seconde2 +5)) { for(i=0;i<200;i++) { buzz=1;) buzz=0;}}/*整点报警*//*void zhengdian (void) { uint k;if((seconde1 == 0)&&(minite1 ==0)){for(bjcs = 0; bjcs<hour1; bjcs++){for(k=0;k<150;k++){buzz=0;delay(20);}buzz=1;delay(20);}}} */void zhengdian (void){if(seconde1==0&&minite1==0){ temp=hour1;flag=1; //标记buzz=1;}}/*主函数*/void main(void){TMOD=0x11; 〃time0为定时器,方式1TH0=0x3c; 〃预置计数初值,50msTL0=0xb0;TH1=(65535-50000)/256;TL1=(65535-50000)%256;EA=1; 〃总中断开ET0=1; 〃允许定时器0中断TR0=1;ET1=1;TR1=1;buzz=0; 〃开启定时器0while (1)(keyscan(); 〃按键扫描dinshi(); 〃定时闹钟〃 zhengdian(); 〃整点报时switch(temp2) 〃显示时间{case 0:display(hour1,minite1,seconde1);break; case1:display(hour2,minite2,seconde2);break;}} void timer0(void) interrupt 1 〃定时器0 方式1, 50ms 中断一次{TH0=0x3c; 〃手动加载计数脉冲次数TL0=0xb0;// TMOD=0x11;mstcnt++;zhengdian(); 〃用于计算时间,每隔50ms加1if(mstcnt==20) //mstcnt 满20 即为一秒{seconde1++; //秒+1time_pro( ); //时间处理mstcnt=0; 〃对计数单元的清零,重新开始计} void timer1() interrupt 3{TH1=(65536-50000)/256;TL1=(65536-50000)%256;if(flag==1){count1++;if(count1<=40)buzz=1;if(40<count1&&count1<80)buzz=0; if(count1==80){count1=0;temp--; // 时间减一}if(temp==0)flag=0;仿真图:。

数字钟程序_EDA

数字钟程序_EDA

--------------------------------------- Title:多功能数字钟---- Author:Pan hongtao ---- Data: 2006-10-1 ---------------------------------------library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;--------------------------------------------------------------------entity digital isport( Clk : in std_logic; --时钟输入Rst : in std_logic; --复位输入S1,S2 : in std_logic; --时间调节输入led : out std_logic_vector(3 downto 0); --整点输报时输出spk : out std_logic;Display : out std_logic_vector(7 downto 0); --八段码管显示输出SEG_SEL : buffer std_logic_vector(2 downto 0) –八段码管扫描驱动);end digital;--------------------------------------------------------------------architecture behave of digital issignal Disp_Temp : integer range 0 to 15; -- 定义整数signal Disp_Decode : std_logic_vector( 7 downto 0);signal SEC1,SEC10 : integer range 0 to 9;signal MIN1,MIN10 : integer range 0 to 9;signal HOUR1,HOUR10 : integer range 0 to 9;signal clk1khz : std_logic;--数码管扫描时钟signal clk1hz : std_logic;--时钟计时时钟signal led_count : std_logic_vector(2 downto 0);signal led_display : std_logic_vector(3 downto 0);signal spkcout : std_logic;beginPROCESS(clk) --产生1hz信号variable cnt : INTEGER RANGE 0 TO 19999999; --产生1Hz时钟的分频计数器BEGINIF clk='1' AND clk'event THENIF cnt=19999999 THEN cnt:=0;ELSEIF cnt<10000000 THEN clk1hz<='1';ELSE clk1hz<='0';END IF;cnt:=cnt+1;END IF;END IF;end process;PROCESS(clk) --产生1khz信号variable cnt1 : INTEGER RANGE 0 TO 19999; --产生1KHz时钟的分频计数器BEGINIF clk='1' AND clk'event THENIF cnt1=19999 THEN cnt1:=0;ELSEIF cnt1<10000 THEN clk1khz<='1';ELSE clk1khz<='0';END IF;cnt1:=cnt1+1;END IF;END IF;end process;process(Clk1Hz,Rst)beginif(Rst='0') then --系统复位SEC1<='0';SEC10<='0';MIN1<='0';MIN10<='0';HOUR1<='0';HOUR10<='0';elsif(Clk1Hz'event and Clk1Hz='1') then --正常运行if(S1='0') then --调节小时if(HOUR1='9') thenHOUR1<='0'; --个位HOUR10<=HOUR10+1; --十位elsif(HOUR10='2' and HOUR1='3') then –在23时HOUR1<='0';HOUR10<='0';elseHOUR1<=HOUR1+1;end if;elsif(S2='0') then --调节分钟if(MIN1='9') thenMIN1<='0';if(MIN10='5') thenMIN10<='0';elseMIN10<=MIN10+1;end if;elseMIN1<=MIN1+1;end if;elsif(SEC1='9') thenSEC1<='0';if(SEC10='5') thenSEC10<='0';if(MIN1='9') thenMIN1<='0';if(MIN10='5') thenMIN10<='0';if(HOUR1='9') thenHOUR1<='0';HOUR10<=HOUR10+1;elsif(HOUR10='2' and HOUR1='3') thenHOUR1<='0';HOUR10<='0';elseHOUR1<=HOUR1+1;end if;elseMIN10<=MIN10+1;end if;elseMIN1<=MIN1+1;end if;elseSEC10<=SEC10+1;end if;elseSEC1<=SEC1+1;end if;end if;end process;process(Clk)--整点报时beginif(Clk1hz'event and Clk1hz='1') thenif(MIN10='5' and MIN1='9' and SEC10='5' and SEC1='5') then --在59分55秒开始提示led_Count<=led_Count+1; spkcout<=not spkcout;elseled_count<="000";spkcout<='0';end if;spk<=spkcout;end if;end process;process(led_count)--整点报时LED灯的闪烁begincase (led_count) iswhen "000"=>led_display<="0000";when "001"=>led_display<="1111";when "010"=>led_display<="0111";when "011"=>led_display<="0011";when "100"=>led_display<="0001";when "101"=>led_display<="1111";when others=>led_display<="0000";end case;led<=led_display;end process;process(SEG_SEL)begincase (SEG_SEL+1) iswhen "111"=>Disp_Temp<=HOUR10;when "110"=>Disp_Temp<=HOUR1;when "101"=>Disp_Temp<=10;when "100"=>Disp_Temp<=MIN10;when "011"=>Disp_Temp<=MIN1;when "010"=>Disp_Temp<=10;when "001"=>Disp_Temp<=SEC10;when "000"=>Disp_Temp<=SEC1;end case;end process;process(Clk1khz)beginif(Clk1khz'event and Clk1khz='1') then --扫描累加SEG_SEL<=SEG_SEL+1;Display<=Disp_Decode;end if;end process;process(Disp_Temp) --显示转换begincase Disp_Temp iswhen '0'=>Disp_Decode<="00111111"; --0when '1'=>Disp_Decode<="00000110"; --1when '2'=>Disp_Decode<="01011011"; --2when '3'=>Disp_Decode<="01001111"; --3when '4'=>Disp_Decode<="01100110"; --4when '5'=>Disp_Decode<="01101101"; --5when '6'=>Disp_Decode<="01111101"; --6when '7'=>Disp_Decode<="00000111"; --7when '8'=>Disp_Decode<="01111111"; --8when '9'=>Disp_Decode<="01101111"; --9when others=>Disp_Decode<="00000000"; --全灭end case;end process;end behave;。

数字时钟课程设计程序

数字时钟课程设计程序

数字时钟课程设计程序一、课程目标知识目标:1. 学生能理解数字时钟的构造原理,掌握时钟的数字显示方法。

2. 学生能掌握时、分、秒的概念,并运用这些概念解读数字时钟。

3. 学生了解数字时钟与日常生活、科技发展的联系。

技能目标:1. 学生能通过实际操作,制作一个简单的数字时钟模型。

2. 学生能运用所学知识,解决数字时钟相关的问题。

3. 学生能运用信息技术手段,收集、整理与数字时钟相关的资料。

情感态度价值观目标:1. 学生培养对数字时钟的兴趣,激发探究时间的欲望。

2. 学生在合作学习中,培养团队协作精神和解决问题的能力。

3. 学生认识到时间的重要性,养成珍惜时间、合理安排时间的习惯。

课程性质:本课程为信息技术与科学相结合的综合性课程,旨在培养学生的动手能力、创新能力和时间观念。

学生特点:六年级学生具有较强的观察力、思维力和动手能力,对新鲜事物充满好奇心。

教学要求:注重理论与实践相结合,引导学生主动探究,关注学生个体差异,提高学生的综合素质。

将课程目标分解为具体的学习成果,以便于后续的教学设计和评估。

二、教学内容1. 数字时钟的基础知识:- 时、分、秒的概念及相互关系- 数字时钟的构造原理及工作方式- 数字时钟的显示方法及特点2. 数字时钟的制作:- 选择合适的材料和工具- 设计数字时钟的电路图- 实际操作,制作数字时钟模型3. 数字时钟的应用与问题解决:- 数字时钟在生活中的应用案例- 运用数字时钟知识解决实际问题- 信息技术手段在数字时钟学习中的应用4. 时间观念与时间管理:- 认识时间的重要性- 学会珍惜时间,合理安排时间- 时间管理的方法与技巧教学内容安排和进度:第一课时:数字时钟基础知识学习第二课时:数字时钟制作(1)第三课时:数字时钟制作(2)第四课时:数字时钟应用与问题解决第五课时:时间观念与时间管理教材章节:- 第四章《电子时钟与计时器》- 第一节《电子时钟的原理与制作》- 第二节《计时器及其应用》教学内容与课本紧密关联,遵循科学性和系统性原则,注重培养学生的动手能力、创新能力和时间观念。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

数字时钟程序/**************************************************程序名称:数字时钟程序全局变量:tt,shi,fen,miao等参数说明:无返回说明:无版本:1.0功能说明:通过数码实现时钟的显示,通过键盘实现时间的调整其中k1是开始调整,k2是增加,k3是减小,k5是实现定时屏幕的切换,k4是定时设置的开始。

带闹铃功能。

作者邮箱:****************(欢迎交流)**************************************************/#include<reg52.h>#define uint unsigned int#define uchar unsigned charsbit beep=P2^3;sbit dula=P2^6;sbit wela=P2^7;sbit k1=P3^0;sbit k2=P3^1;sbit k3=P3^2;sbit k4=P3^3;sbit k5=P3^4;sbit rd=P3^7;uchartt,shi_s,shi_g,shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g,fen_s,fen_g,miao_s,miao_g,k1num,k 4num,flag;char shi,fen,miao=20,shi1,fen1,miao1;/*********************************函数名称:延时程序设计全局变量:无参数说明:z传递给内部,是实现75*z条空指令延迟返回说明:无版本:1.0功能说明:约Z*75us延时程序设计作者邮箱:****************(欢迎交流)*********************************/void delay(uint z){uchar x;uint y;for(x=z;x>0;x--)for(y=75;y>0;y--);}/********八段数码管编码**********/uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};/*********************************函数名称:初始化函数全局变量:无参数说明:无返回说明:无版本:1.0功能说明:定时器装初值,开总中断,定时中断,并写定时中断函数作者邮箱:****************(欢迎交流)*********************************/void init(){TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;}void timer0() interrupt 1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;tt++;if(tt==20){tt=0;miao++;if(miao==60){miao=0;fen++;if(fen==60){fen=0;shi++;if(shi==24){shi=0;}}}}}/*********************************函数名称:6个数码管显示函数全局变量:shi fen miao 的个十位分离参数说明:将个十位的分离分别传递到各个数码管中并显示返回说明:无版本:1.0功能说明:实现时钟的数码管显示,动态扫描。

作者邮箱:****************(欢迎交流)*********************************/void display(uchar shi_s,uchar shi_g,uchar fen_s,uchar fen_g,uchar miao_s,uchar miao_g) {P0=0xfe;wela=1;wela=0;dula=1;P0=table[shi_s];dula=0;delay(2);wela=1;P0=0xfd;wela=0;dula=1;P0=table[shi_g]+0x80;dula=0;delay(2);wela=1;P0=0xfb;wela=0;dula=1;P0=table[fen_s];dula=0;delay(2);wela=1;P0=0xf7;wela=0;dula=1;P0=table[fen_g]+0x80;dula=0;delay(2);wela=1;P0=0xef;wela=0;dula=1;P0=table[miao_s];dula=0;delay(2);wela=1;P0=0xdf;wela=0;dula=1;P0=table[miao_g];dula=0;delay(2);}/*********************************函数名称:键盘控制时钟调节函数全局变量:已说明参数说明:已声明了返回说明:无版本:1.0功能说明:通过键盘的选择,和数码管进行结合并显示所调节的时间及定时的时间作者邮箱:****************(欢迎交流)*********************************/void keyscan(){rd=0;if(k5==0){delay(5);if(k5==0){flag++;while(!k5);while(k5&&flag%2==1){shi1_s=shi1/10;shi1_g=shi1%10;fen1_s=fen1/10;fen1_g=fen1%10;miao1_s=miao1/10;miao1_g=miao1%10;display(shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g);if(k4==0){delay(5);if(k4==0){k4num++;while(!k4);if(k4num==4)k4num=0;display(shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g);}}if(k4num!=0){if(k2==0){delay(5);if(k2==0){while(!k2);if(k4num==1){miao1++;if(miao1==60)miao1=0;display(shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g);}if(k4num==2){fen1++;if(fen1==60)fen1=0;display(shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g);}if(k4num==3){shi1++;if(shi1==60)shi1=0;display(shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g);}}}if(k3==0){delay(5);if(k3==0){while(!k3);if(k4num==1){miao1--;if(miao1==-1)miao1=59;display(shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g);}if(k4num==2){fen1--;if(fen1==-1)fen1=59;display(shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g);}if(k4num==3){shi1--;if(shi1==-1)shi1=23;display(shi1_s,shi1_g,fen1_s,fen1_g,miao1_s,miao1_g);}}}}}}}if(k1==0){delay(5);if(k1==0){ k1num++;while(!k1);if(k1num==1){TR0=0;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);}}if(k1num==4){k1num=0;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);TR0=1;}}if(k1num!=0){if(k2==0){delay(5);if(k2==0){while(!k2);if(k1num==1){miao++;if(miao==60)miao=0;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);}if(k1num==2){fen++;if(fen==60)fen=0;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);}if(k1num==3){shi++;if(shi==24)shi=0;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);}}}if(k3==0){delay(5);if(k3==0){while(!k3);if(k1num==1){miao--;if(miao==-1)miao=59;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);}if(k1num==2){fen--;if(fen==-1)fen=59;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);}if(k1num==3){shi--;if(shi==-1)shi=23;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);}}}}}/*********************************函数名称:数字时钟程序主程序全局变量:在程序开头已声明了参数说明:已说明了返回说明:无版本:1.0功能说明:程序的入口,且停留在函数内部作者邮箱:****************(欢迎交流)*********************************/void main(){init();while(1){shi_s=shi/10;shi_g=shi%10;fen_s=fen/10;fen_g=fen%10;miao_s=miao/10;miao_g=miao%10;display(shi_s,shi_g,fen_s,fen_g,miao_s,miao_g);keyscan();if(shi1==shi&&fen1==fen&&miao1==miao){beep=0;}}}。

相关文档
最新文档