基于单片机的万年历源代码程序Word格式文档下载.docx
- 文档编号:17532307
- 上传时间:2022-12-07
- 格式:DOCX
- 页数:43
- 大小:21.88KB
基于单片机的万年历源代码程序Word格式文档下载.docx
《基于单片机的万年历源代码程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《基于单片机的万年历源代码程序Word格式文档下载.docx(43页珍藏版)》请在冰豆网上搜索。
while(i--)
for(j=76;
j>
1;
j--);
for(k=29;
k>
k--);
}
voiddelaynus(unsignedcharn)//延时若干微秒
unsignedchari;
for(i=0;
i<
n;
i++);
}
/***********蜂鸣器模块************/
sbitbeep=P3^6;
//位定义,定义P.6位fmp
voiddely500(void)
for(i=250;
i>
0;
i--)
{
_nop_();
voidbaojing(unsignedcharn)
unsignedcharx,i;
while(n--)
for(i=0;
5;
i++)
for(x=0;
x<
200;
x++)
beep=~beep;
dely500();
3;
/*******DS1302模块*************/
voidWrite1302(unsignedchardate)//向1302写数据
unsignedchari;
SCLK=0;
delaynus
(2);
8;
DATE=date&
0x01;
SCLK=1;
delaynus
(2);
SCLK=0;
date>
>
=1;
voidWriteSet1302(unsignedcharcmd,unsignedchardate)//根据相应的命令输入相应的数据
REST=0;
REST=1;
Write1302(cmd);
delaynus(5);
Write1302(date);
SCLK=1;
REST=0;
unsignedcharRead1302(void)//读取1302数据
unsignedchari,date;
if(DATE==1)
date|=0x80;
returndate;
unsignedcharReadSet1302(unsignedcharcmd)//根据命令读取1302相应的值
unsignedchardate;
REST=0;
REST=1;
Write1302(cmd);
date=Read1302();
SCLK=1;
voidIntDS1302(void)//DS1302初始化
{
unsignedcharflag;
flag=ReadSet1302(0x81);
if(flag&
0x80){//判断时钟芯片是否关闭
WriteSet1302(0x8E,0x00);
//根据写状态寄存器命令字,写入不保护指令
WriteSet1302(0x80,((0/10)<
<
4|(0%10)));
//根据写秒寄存器命令字,写入秒的初始值
WriteSet1302(0x82,((0/10)<
//根据写分寄存器命令字,写入分的初始值
WriteSet1302(0x84,((0/10)<
//根据写小时寄存器命令字,写入小时的初始值
WriteSet1302(0x86,((0/10)<
//根据写日寄存器命令字,写入日的初始值
WriteSet1302(0x88,((0/10)<
//根据写月寄存器命令字,写入月的初始值
WriteSet1302(0x8c,((10/10)<
4|(10%10)));
//根据写年寄存器命令字,写入年的初始值
WriteSet1302(0x90,0xa5);
//打开充电功能选择2K电阻充电方式
WriteSet1302(0x8E,0x80);
//根据写状态寄存器命令字,写入保护指令
/***************液晶显示模块*****************/
sbitRS=P2^5;
sbitRW=P2^6;
sbitE=P2^7;
sbitBF=P0^7;
/*液晶忙检测*/
bitBusyTest(void)
bitresult;
RS=0;
RW=1;
E=1;
result=BF;
E=0;
returnresult;
/*写指令*/
voidWrite_com(unsignedcharcommand)
while(BusyTest()!
=0);
RW=0;
P0=command;
_nop_();
/*写地址*/
voidWrite_Address(unsignedcharaddress)
Write_com(address|0x80);
delay1ms
(1);
}
/*写数据*/
voidWrite_Date(unsignedchardate)
RS=1;
P0=date;
/*初始化*/
voidLcd_Int(void)
Write_com(0x38);
Write_com(0x06);
Write_com(0x0c);
Write_com(0x01);
voiddisplaymainpart(void)//显示液晶主要部分(不变化部分)
Write_Address(0x01);
Write_Date('
D'
);
A'
T'
E'
:
'
Write_Address(0x0A);
-'
Write_Address(0x0D);
Write_Address(0x42);
I'
M'
Write_Address(0x4A);
Write_Address(0x4D);
Write_Address(0x06);
2'
0'
voiddisplay_Second(unsignedcharsecond)//在液晶上显示秒
unsignedchari,j;
i=second/10;
j=second%10;
Write_Address(0x4E);
Write_Date(digit[i]);
Write_Date(digit[j]);
voiddisplay_Minute(unsignedcharminute)//在液晶上显示分
i=minute/10;
j=minute%10;
Write_Address(0x4B);
Write_Date(digit[j]);
voiddisplay_Hour(unsignedcharhour)//在液晶上显示时
i=hour/10;
j=hour%10;
Write_Address(0x48);
voiddisplay_Day(unsignedcharday)//在液晶上显示日
i=day/10;
j=day%10;
Write_Address(0x0E);
voiddisplay_Month(unsignedcharmonth)//在液晶上显示月
i=month/10;
j=month%10;
Write_Address(0x0B);
voiddisplay_Year(unsignedcharyear)//在液晶上显示年
i=year/10;
j=year%10;
Write_Address(0x08);
voiddisplay_houra(unsignedcharx)//闹钟小时部分显示
i=x/10;
j=x%10;
Write_Address(0x44);
voiddisplay_minutea(unsignedcharx)//闹钟分钟部分显示
Write_Address(0x47);
voiddisplay_Time(void)//显示实时时间
unsignedcharvalue,day,month,year;
value=ReadSet1302(0x81);
seconds=(((value&
0x70)>
4)*10+(value&
0x0f));
display_Second(seconds);
value=ReadSet1302(0x83);
minutes=(((value&
display_Minute(minutes);
value=ReadSet1302(0x85);
hours=(((value&
display_Hour(hours);
value=ReadSet1302(0x87);
day=(((value&
display_Day(day);
value=ReadSet1302(0x89);
month=(((value&
display_Month(month);
value=ReadSet1302(0x8D);
year=(((value&
0xf0)>
display_Year(year);
voiddisplaystar(void)//显示欢迎界面
Write_Address(0x0f);
while(displaywelcome[i]!
='
\0'
)
Write_Date(displaywelcome[i]);
i++;
delay1ms
(1);
i=0;
Write_Address(0x4f);
while(displaywish[i]!
Write_Date(displaywish[i]);
j=40;
while(j--)
Write_com(0x18);
//循环左移
delay1ms(700);
}
delay1ms(10);
voidgbdisplay(unsignedcharaddress)//时间调整时光标闪烁
Write_Address(address);
delay1ms(5);
Write_com(0x0f);
voiddisplaymaxt(unsignedcharx)//显示最大温度
unsignedchari,j,k;
delay1ms
(2);
i=x/100;
j=x/10;
k=x%10;
Write_Date(digit[k]);
/*****************时间调整部分*********************/
voidhourset(void)//调时
unsignedchartimevalue,hour;
delay1ms(500);
//防止多次触发
WriteSet1302(0x8e,0x00);
//将写保护去掉,确保能正常将调整后的数值写入DS1302
timevalue=ReadSet1302(0x85);
//读取此时的数值
hour=(((timevalue&
4)*10+(timevalue&
while
(1)
if(ADD==0)
{
delay1ms(50);
if(ADD==0)
{
hour++;
delay1ms(300);
while(ADD==0);
}
}
if(RED==0)
if(RED==0)
hour--;
if(hour==0)hour=23;
while(RED==0);
timevalue=(((hour)/10)<
4|(hour%10));
WriteSet1302(0x84,timevalue);
display_Hour(hour);
Write_Address(0x49);
delay1ms(5);
if(hour>
=24)hour=0;
if(CANL==0)
mode=0;
Write_com(0x0c);
break;
if(SET==0)break;
WriteSet1302(0x8e,0x80);
voidminuteset(void)//调分
unsignedchartimevalue,minute;
timevalue=ReadSet1302(0x83);
minute=(((timevalue&
delay1ms(10);
minute++;
if(minute>
=60)timevalue=0;
minute--;
if(minute==0)minute=59;
timevalue=((minute/10)<
4|(minute%10));
WriteSet1302(0x82,timevalue);
display_Minute(minute);
Write_Address(0x4c);
if(minute>
=60)minute=0;
voidsecondset(void)//秒归零
unsignedcharsecond;
second=0;
WriteSet1302(0x80,0x00);
display_Second(second);
Write_Address(0x4f);
voidyearset(void)//调年
unsignedchardatevalue,year;
WriteSet1302(0x8e,0x00);
datevalue=ReadSet1302(0x8d);
year=(((datevalue&
4)*10+(datevalue&
year++;
year--;
datevalue=((year/10)<
4|(year%10));
WriteSet1302(0x8c,datevalue);
display_Year(year);
del
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 单片机 万年历 源代码 程序