资源简介

基于单片机的简易数字时钟仿真,课程设计结果。 (1)时间可调整。 (2)有闹钟功能。 (3)利用数码管或者液晶显示器显示时间(XX-XX-XX 由左向右分别为:时、分、秒,且每秒更新一次)。 (4)整点报时

资源截图

代码片段和文件信息

#include 
#include “8.h“
SYSTEMTIME time1;
SYSTEMTIME clocktime;

void displaytime()
{
DS1302_GetTime(&time1);
if(Change12_24)
time1.Hour %= 12;
TimeToStr(&time1);
GotoXY(71);
Print(time1.TimeString);
}
void clock()
{
GotoXY(00);
Print(“clock: “);
TimeToStr(&clocktime);
GotoXY(70);
Print(clocktime.TimeString);

while((key1 == 1) || (key2 == 1)) //按键key1或key2默认为高电平,此句进入循环 

if(key1 == 0) //key1键调时间
{
Delay1ms(100);
if(key1 == 0)
{
if(option == 0)
{
clocktime.Hour++;
if(Change12_24)
clocktime.Hour %= 12;
else
clocktime.Hour %= 24;
}
else if(option == 1)
{
clocktime.Minute++;
clocktime.Minute %= 60;
}
else

clocktime.Second++;
clocktime.Second %= 60;
}
TimeToStr(&clocktime);
GotoXY(70);
Print(clocktime.TimeString);
}
}

if(key2 == 0) //key2键选择时分秒
{
Delay1ms(100);
if(key2 == 0)
{
option ++;
option %= 3;
}
}

if(key0 == 0) //key0退出
{
Delay1ms(100);
if(key0 == 0)
break;
}
displaytime();
}
}
void time_set()
{
GotoXY(00);
Print(“chang: “);

DS1302_GetTime(&time1);

if(Change12_24)
time1.Hour %= 12;

TimeToStr(&time1);
GotoXY(70);
Print(time1.TimeString);

while((key1 == 1) || (key2 == 1))  
{
if(key1 == 0) //key1调节时间
{
Delay1ms(100);
if(key1 == 0)
{
if(option == 0)
{
time1.Hour++;
if(Change12_24)
time1.Hour %= 12;
else
time1.Hour %= 24;
}
else if(option == 1)
{
time1.Minute++;
time1.Minute %= 60;
}
else

time1.Second++;
time1.Second %= 60;
}

DS1302_SetTime(ds_hour time1.Hour);
DS1302_SetTime(ds_minute time1.Minute);
DS1302_SetTime(ds_second time1.Second);

DS1302_GetTime(&time1);
if(Change12_24)
time1.Hour %= 12;
TimeToStr(&time1);
GotoXY(70);
Print(time1.TimeString);
}
}

if(key2 == 0)   //key2选择时分秒
{
Delay1ms(100);
if(key2 == 0)
{
option ++;
option %= 3;
}
}

if(key0 == 0)  //key0退出
{
Delay1ms(100);
if(key0 == 0)
break;
}
   displaytime();
}
}
void sec_watch()
{
char secondwatch[9];
unsigned int count = 0;
secondwatch[8] = ‘\0‘;

GotoXY(00);
Print(“watch: 00:00:00“);

while((key1 == 1) || (key2 == 1))  
{  


if(key1 == 0) //key1开始计时
{
Delay1ms(100);
if(key1 == 0)
{
while(key2 == 1)  //key2停止计时
{
    Delay1ms(10);
count++;
secondwatch[0] = count/3600/10 + ‘0‘;
secondwatch[1] = count/3600%10 + ‘0‘;
secondwatch[2] = ‘:‘;
secondwatch[3] = (count/60%60)/10 + ‘0‘;
secondwatch[4] = (count/60%60)%10 + ‘0‘;
secondwatch[5] = ‘:‘;
secondwatch[6] = count%60/10 + ‘0‘;
secondwatch[7] =

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-12-30 15:59  数字时钟\
     目录           0  2016-12-30 16:40  数字时钟\数字时钟4\
     文件       13796  2010-12-28 20:59  数字时钟\数字时钟4\1228.LST
     文件        9732  2010-12-28 20:59  数字时钟\数字时钟4\1228.OBJ
     文件       26571  2010-12-29 08:26  数字时钟\数字时钟4\4
     文件        6701  2010-12-29 08:26  数字时钟\数字时钟4\4.hex
     文件          35  2010-12-29 08:26  数字时钟\数字时钟4\4.lnp
     文件       32758  2010-12-29 08:26  数字时钟\数字时钟4\4.M51
     文件        1344  2010-12-29 08:30  数字时钟\数字时钟4\4.Opt
     文件        9879  2010-12-29 08:30  数字时钟\数字时钟4\4.plg
     文件        2141  2010-12-29 08:28  数字时钟\数字时钟4\4.Uv2
     文件        1345  2010-12-29 08:28  数字时钟\数字时钟4\4_Opt.Bak
     文件        2143  2010-12-28 21:01  数字时钟\数字时钟4\4_Uv2.Bak
     文件        5588  2010-12-29 08:26  数字时钟\数字时钟4\8.c
     文件        6027  2010-12-29 08:01  数字时钟\数字时钟4\8.h
     文件       18316  2010-12-29 08:26  数字时钟\数字时钟4\8.LST
     文件       30402  2010-12-29 08:26  数字时钟\数字时钟4\8.OBJ
     文件        6376  2005-03-22 15:22  数字时钟\数字时钟4\STARTUP.A51
     文件       14048  2010-12-28 20:30  数字时钟\数字时钟4\STARTUP.LST
     文件         749  2010-12-28 20:30  数字时钟\数字时钟4\STARTUP.OBJ
     文件      118983  2010-12-29 08:29  数字时钟\数字时钟4\时钟仿真.DSN
     文件         935  2016-12-30 16:40  数字时钟\数字时钟4\时钟仿真.PWI

评论

共有 条评论