#include"tiaoshi.h"
#include"key.h"
#include"ds1302.h"
#include"lcd1602.h"
calendar g_calendar;
u8 time_buf[17];u8 date_buf[10];
u8 alarm_key=0;
//进入时间设置模式前将ds1302中的时间数据提取到变量中操作
void time_set_before_read()
{
g_calendar.sec=gDS1302_TIME[0];//
g_calendar.min=gDS1302_TIME[1];
g_calendar.hour=gDS1302_TIME[2];
g_calendar.day=gDS1302_TIME[3];
g_calendar.mouth=gDS1302_TIME[4];
g_calendar.week=gDS1302_TIME[5];
g_calendar.year=gDS1302_TIME[6];
}
//将设置好的时间发送给ds1302,设置保存
void time_set_save()
{
gDS1302_TIME[0]=g_calendar.sec;//
gDS1302_TIME[1]=g_calendar.min;
gDS1302_TIME[2]=g_calendar.hour;
gDS1302_TIME[3]=g_calendar.day;
gDS1302_TIME[4]=g_calendar.mouth;
gDS1302_TIME[5]=g_calendar.week;
gDS1302_TIME[6]=g_calendar.year;
ds1302_init();
}
//将所要显示的数据封存在两个数组中,在lcd1602函数通过指针读出其中数据,然后发送给1602显示
void time_show()
{
if(g_calendar.time_set_mode==0||g_calendar.time_set_mode==1)//时钟模式以及时钟设置模式显示
{
time_buf[0]='2';
time_buf[1]='0';
time_buf[2]=(g_calendar.year/16)+0x30;//16进制
time_buf[3]=(g_calendar.year%16)+0x30;
time_buf[4]='-';
time_buf[5]=(g_calendar.mouth/16)+0x30;
time_buf[6]=(g_calendar.mouth%16)+0x30;
time_buf[7]='-';
time_buf[8]=(g_calendar.day/16)+0x30;
time_buf[9]=(g_calendar.day%16)+0x30;
time_buf[10]='-';
time_buf[11]='D';
time_buf[12]='a';
time_buf[13]='y';
time_buf[14]=(g_calendar.week%16)+0x30;
time_buf[15]='\0';
date_buf[0]=(g_calendar.hour/16)+0x30;
date_buf[1]=(g_calendar.hour%16)+0x30;
date_buf[2]=':';
date_buf[3]=(g_calendar.min/16)+0x30;
date_buf[4]=(g_calendar.min%16)+0x30;
date_buf[5]=':';
date_buf[6]=(g_calendar.sec/16)+0x30;
date_buf[7]=(g_calendar.sec%16)+0x30;
date_buf[8]='\0';
}
else//闹钟模式下显示“alarm:”
{
time_buf[0]='A';
time_buf[1]='l';
time_buf[2]='a';//16进制
time_buf[3]='r';
time_buf[4]='m';
time_buf[5]=':';
time_buf[9]=' ';
time_buf[10]=' ';
time_buf[11]=' ';
time_buf[12]=' ';
time_buf[13]=' ';
time_buf[14]=' ';
time_buf[15]='\0';
if(g_calendar.alarm_on_off==0)//如果闹钟关闭则显示:off
{
time_buf[6]='o';
time_buf[7]='f';
time_buf[8]='f';
}
else if(g_calendar.alarm_on_off==1)//否则显示:on
{
time_buf[6]='o';
time_buf[7]='n';
time_buf[8]=' ';
}
date_buf[0]=(g_calendar.alarm[2]/16)+0x30;//显示设置闹钟的值
date_buf[1]=(g_calendar.alarm[2]%16)+0x30;
date_buf[3]=(g_calendar.alarm[1]/16)+0x30;
date_buf[4]=(g_calendar.alarm[1]%16)+0x30;
date_buf[6]=(g_calendar.alarm[0]/16)+0x30;
date_buf[7]=(g_calendar.alarm[0]%16)+0x30;
}
lcd1602_show_string(0,0,time_buf);//第一行显示发送
lcd1602_show_string(0,1,date_buf);//第二行显示发送
}
void time_add1()//时间加1
{
if(g_calendar.time_set_mode==0||g_calendar.time_set_mode==1)
{
switch(g_calendar.time_set_choice)
{
case 0:
if((++g_calendar.sec&0x0f)>9)g_calendar.sec+=6;
if(g_calendar.sec>=0x60)g_calendar.sec=0;
break;
case 1:
if((++g_calendar.min&0x0f)>9)g_calendar.min+=6;
if(g_calendar.min>=0x60)g_calendar.min=0;
break;
case 2:
if((++g_calendar.hour&0x0f)>9)g_calendar.hour+=6;
if(g_calendar.hour>=0x24)g_calendar.hour=0;
break;
case 3:
if((++g_calendar.week&0x0f)>=8)g_calendar.week=1;
break;
case 4:
if((++g_calendar.day&0x0f)>9) g_calendar.day+=6;
if(g_calendar.day>0x32) g_calendar.day=0x01;
break;
case 5:
if((++g_calendar.mouth&0x0f)>9) g_calendar.mouth+=6;
if(g_calendar.mouth>0x12) g_calendar.mouth=0x01;
break;
case 6:
if((++g_calendar.year&0x0f)>9) g_calendar.year+=6;
if(g_calendar.year>0x29) g_calendar.year=0x00;
break;
}
}
else
{
switch(g_calendar.time_set_choice)
{
case 0: if((++g_calendar.alarm[0]&0x0f)>9) g_calendar.alarm[0]+=6;
if(g_calendar.alarm[0]>=0x60) g_calendar.alarm[0]=0;
break;
case 1: if((++g_calendar.alarm[1]&0x0f)>9) g_calendar.alarm[1]+=6;
if(g_calendar.alarm[1]>=0x60) g_calendar.alarm[1]=0;
break;
case 2: if((++g_calendar.alarm[2]&0x0f)>9)g_calendar.alarm[2]+=6;
if(g_calendar.alarm[2]>=0x24)g_calendar.alarm[2]=0;
break;
}
}
}
void time_subtract1()//时间减1
{
if(g_calendar.time_set_mode==0||g_calendar.time_set_mode==1)
{
switch(g_calendar.time_set_choice)
{
case 0:
if((--g_calendar.sec&0x0f)>=0x0f) g_calendar.sec-=6;
if(g_calendar.sec<0x00) g_calendar.sec=0x60;
break;
case 1:
if((--g_calendar.min&0x0f)>=0x0f) g_calendar.min-=6;
if(g_calendar.min<0x00) g_calendar.min=0x60;
break;
case 2:
if((--g_calendar.hour&0x0f)>=0x0f) g_calendar.hour-=6;
if(g_calendar.hour<0x00) g_calendar.hour=0x23;
break;
case 3:
if((--g_calendar.week&0x0f)<=0) g_calendar.week=7;
break;
case 4:
if((--g_calendar.day&0x0f)>=0x0f) g_calendar.day-=6;
if(g_calendar.day<0x01) g_calendar.day=0x32;
break;
case 5:
if((--g_calendar.mouth&0x0f)>=0x0f) g_calendar.mouth-=6;
if(g_calendar.mouth<0x01) g_calendar.mouth=0x12;
break;
case 6:
if((--g_calendar.year&0x0f)>=0x0f) g_calendar.year-=6;
if(g_calendar.year<0x01) g_calendar.year=0x29;
break;
}
}
else
{
switch(g_calendar.time_set_choice)
{
case 0:
if((--g_calendar.alarm[0]&0x0f)>=0x0f) g_calendar.alarm[0]-=6;
if(g_calendar.alarm[0]<0x00) g_calendar.alarm[0]=0x60;
break;
case 1:
if((--g_calendar.alarm[1]&0x0f)>=0x0f) g_calendar.alarm[1]-=6;
if(g_calendar.alarm[1]<0x00) g_calendar.alarm[1]=0x60;
break;
case 2:
if((--g_calendar.alarm[2]&0x0f)>=0x0f) g_calendar.alarm[2]-=6;
if(g_calendar.alarm[2]<0x00) g_calendar.alarm[2]=0x23;
break;
}
}
}
void calendar_()
{
u8 key_buf=0;//键值缓存
g_calendar.time_set_choice=0;//初始化值为0
g_calendar.time_set_mode=0;
g_calendar.alarm_on_off=0;//初始关闭闹钟
while(1)
{
key_buf=key_matrix_flip_scan();//记录键值
switch(g_calendar.time_set_mode)
{
case 0: /************时钟显示模式**************/
if(key_buf==1)
{
time_set_before_read();//切换模式前拷贝ds1302中时间数据
g_calendar.time_set_choice=0;
g_calendar.time_set_mode++;//模式位加1,切换模式
}
ds1302_read_time();//读时间
time_set_before_read();//时间数据存到七个变量中
time_show();//显示时间
break;
case 1:/************时钟调节模式*************/
switch(key_buf)
{
case 1://1键切换模式,不保存设置过的时间
{
g_calendar.time_set_mode++;
g_calendar.time_set_choice=0;
break;
}
case 2://2键保存设置
g_calendar.time_set_mode=0;
//调整后时间发送给ds1302,即保存时间
time_set_save();
break;
case 3://3键调整要改变的位
g_calendar.time_set_choice++;
if(g_calendar.time_set_choice==7) g_calendar.time_set_choice=0;
break;
case 4: time_add1();break;//当前位,时间加1
case 5: time_subtract1();break;//当前位,时间减1
}
time_show();//显示
break;
case 2:/**********闹钟调节模式**********/
switch(key_buf)
{
case 1:
g_calendar.time_set_mode++;
if(g_calendar.time_set_mode>=3) g_calendar.time_set_mode=0;
g_calendar.alarm[0]=0x30;
g_calendar.alarm[1]=0x30;
g_calendar.alarm[2]=0x12;
break;
case 2:
g_calendar.time_set_mode=0;break;//2键保存设置
case 3:
g_calendar.time_set_choice++;
if(g_calendar.time_set_choice==4) g_calendar.time_set_choice=0;
break;
case 4:
if(g_calendar.time_set_choice==3)
{
switch(g_calendar.alarm_on_off)
{
case 0:
没有合适的资源?快使用搜索试试~ 我知道了~
stc89c52rc单片机电子万年历(ds1302+lcd1602显示)软件KEIL工程源码.zip
共33个文件
lst:6个
c:6个
obj:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 12 下载量 129 浏览量
2022-03-29
15:03:54
上传
评论 9
收藏 69KB ZIP 举报
温馨提示
stc89c52rc单片机电子万年历(ds1302+lcd1602显示)软件KEIL工程源码,可以显示:年月日周秒分时,可以进行时间调节,可以设置闹钟。 #include"lcd1602.h" #include"public.h" #include"ds1302.h" #include"key.h" #include"tiaoshi.h" void main() { ds1302_init(); lcd1602_init(); calendar_();//在调试中源文件中可以找到该函数 while(1) { } }
资源推荐
资源详情
资源评论
收起资源包目录
stc89c52rc单片机电子万年历(ds1302+lcd1602)软件KEIL工程源码.zip (33个子文件)
电子万年历
public
public.c 247B
public.h 243B
lcd1602.uvopt 62KB
obj
tiaoshi.lst 33KB
lcd1602.lnp 186B
lcd1602.hex 7KB
public.obj 3KB
ds1302.lst 5KB
public.lst 2KB
tiaoshi.obj 18KB
main.obj 4KB
main.lst 1KB
lcd1602.plg 17KB
key.lst 4KB
lcd1602.m51 34KB
ds1302.obj 6KB
lcd1602.obj 6KB
key.obj 3KB
lcd1602.lst 4KB
lcd1602 34KB
app
key
key.c 1KB
key.h 336B
tiaoshi
tiaoshi.h 296B
tiaoshi.c 13KB
lcd1602
lcd1602.c 2KB
lcd1602.h 335B
ds1302
ds1302.c 2KB
ds1302.h 426B
lcd1602.uvproj 14KB
user
main.c 224B
lcd1602.plg 181B
lcd1602_uvproj.bak 14KB
lcd1602_uvopt.bak 62KB
共 33 条
- 1
SKCQTGZX
- 粉丝: 86
- 资源: 5821
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页