嵌入式电子闹钟时钟课程设计Word格式.docx
《嵌入式电子闹钟时钟课程设计Word格式.docx》由会员分享,可在线阅读,更多相关《嵌入式电子闹钟时钟课程设计Word格式.docx(15页珍藏版)》请在冰豆网上搜索。
液晶写数据函数
芯片写指令函数
时间设置函数
进制转换函数
读时间函数闹钟函数
延时函数
ucharnum,count,shi,fen,miao,s1num,s2num,
year,month,day,week,flag,flag1,year1,month1,
day1,week1,shi1,fen1,miao1,year2,month2,
day2,week2,shi2,fen2,miao2,year5,month5,day5,week5,shi5,fen5,miao5,wk,ashi,afen;
//参数定义
ucharcodetable[]="
20——"
;
//ucharcodetable1[]="
:
00:
00”;
/*
uchartime_dat[7]={12,1,6,6,12,59,59};
//ucharwrite_add[7]={0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};
ucharread_add[7]={0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};
*/voidwrite_com(ucharcom);
//
voidwrite_data(uchardate);
voidwrite_ds1302(ucharadd,uchardat);
//ds1302
voidset_rtc();
voidtime_pros();
voidread_rtc();
voidalarm();
voiddelay(uintz)//
{
uintx,y;
for(x=z;
x>
0;
x-—)for(y=110;
y〉0;
y--);
voidinit()
{
lcden=0;
flag=0;
flag1=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
//for(num=0;
num<
14;
num++){
write_data(table[num]);
delay(5);
}
write_com(0x80+0x40);
num〈20;
write_data(table1[num]);
delay(5);
初始化
液晶固定显示,第一行
液晶显示第二行
voidwrite_com(ucharcom)//1602液晶写指令{
rs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
voidwrite_data(uchardate)//1602液晶写写数据{
rs=1;
P0=date;
lcden=1;
lcden=0;
voidwrite_sfm(ucharadd,uchardate)//时分秒{
ucharshi3,ge;
shi3=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_data(0x30+shi3);
write_data(0x30+ge);
voidwrite_nyr(ucharad,uchardate)//年月日
ucharshi4,ge2;
shi4=date/10;
ge2=date%10;
write_com(0x80+ad);
write_data(0x30+shi4);
write_data(0x30+ge2);
星期天为第一天
voidwrite_week(ucharwk)//星期按西方星期设置{
write_com(0x80+11);
switch(wk)
case1:
write_data('
S’);
U’);
write_data(’N’);
break;
case2:
M’);
O’);
N’);
case3:
T'
);
U'
E'
);
break;
case4:
W’);
write_data(’E’);
D’);
case5:
write_data(’H’);
case6:
F’);
R’);
T’);
case7:
S'
write_data(’A'
write_data(’T'
voidkeyscan()
if(s1==0)
write_com(0x0f);
s1num++;
//flag=1;
flag1=1;
while(!
s1);
记录按键次数
switch(s1num)//光标闪烁点定位
case1:
write_com(0x80+0x40+6);
//秒break;
write_com(0x80+0x40+3);
//分break;
case3:
write_com(0x80+0x40+0);
//时break;
case4:
write_com(0x80+11);
//break;
case5:
write_com(0x80+8);
//break;
星期
日
write_com(0x80+5);
case7:
write_com(0x80+2);
case8:
s1num=0;
write_com(0x0c);
//间设置
set_rtc();
flag=0;
}
设置开显示光标不显示
关闭时
if(s1num!
=0)//{
按键加减
if(s2==0)
加按键函数
delay(10);
if(s2==0){
while(!
s2);
switch(s1num)//根据功能键相应次数做出调节
miao++;
//秒加if(miao==60)miao=0;
write_sfm(6,miao);
write_com(0x80+0x40+6);
case2:
fen++;
//分加if(fen==60)
fen=0;
write_sfm(3,fen);
write_com(0x80+0x40+3);
shi++;
//时加if(shi==24)
shi=0;
write_sfm(0,shi);
write_com(0x80+0x40+0);
星期加
week++;
//if(week==8)week=1;
write_week(week);
write_com(0x80+11);
day++;
//if(day==32)day=1;
write_nyr(8,day);
write_com(0x80+8);
if(month==13)
month=1;
write_nyr(5,month);
write_com(0x80+5);
year++;
年加
if(year==100)
year=0;
write_nyr(2,year);
write_com(0x80+2);
break;
if(s3==0)//减按键函数同上{
delay(10);
if(s3==0)
s3);
miao—-;
if(miao==—1)
miao=59;
write_sfm(6,miao);
write_com(0x80+0x40+6);
fen——;
if(fen==-1)
fen=59;
write_sfm(3,fen);
write_com(0x80+0x40+3);
shi—-;
if(shi==—1)
shi=23;
write_sfm(0,shi);
week--;
if(week==—1)week=7;
write_week(week);
write_com(0x80+11);
day--;
if(day==-1)day=31;
write_com(0x80+8);
case6:
month—-;
if(month==—1)month=12;
write_nyr(5,month);
write_com(0x80+5);
year-—;
if(year==—1)year=99;
write_nyr(2,year);
write_com(0x80+2);
if(s4==0)//{
闹钟按键
if(s4==0)
//s2num++;
//flag=1;
s4);
switch(s2num)//
光标闪烁
光标闪烁点定位
write_com(0x80+0x40+13);
write_com(0x80+0x40+10);