万年历初始源程序Word文档下载推荐.docx
- 文档编号:16857616
- 上传时间:2022-11-26
- 格式:DOCX
- 页数:20
- 大小:17.76KB
万年历初始源程序Word文档下载推荐.docx
《万年历初始源程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《万年历初始源程序Word文档下载推荐.docx(20页珍藏版)》请在冰豆网上搜索。
ucharhour=10;
ucharmin=18;
ucharsec=30;
ucharyear=10;
ucharmon=1;
uchardate=20;
ucharday=3;
ucharcount=0;
ucharflag=0;
ucharnum=0;
uchari=6;
voiddelay(uinti)
{
uintj;
for(;
i>
0;
i--)
for(j=0;
j<
125;
j++);
}
voidWrite_Ds1302_Byte(uchartemp)
uchari;
for(i=0;
i<
8;
i++)
{
SCLK=0;
IO=temp&
0x01;
//只传最后一位
temp>
>
=1;
SCL=1;
}
voidWrite_Ds1302(ucharaddress,uchardat)
RST=0;
RST=1;
Write_Ds1302_Byte(address);
Write_Ds1302_Byte(dat);
SCLK=1;
ucharRead_Ds1302(ucharaddress)
uchari,temp=0x00;
if(IO)
temp=temp|0x80;
IO=0;
returntemp;
voidCheck_Busy(void)
RW=1;
//RW=1为读
RS=0;
//RS=0为指令
EN=1;
while(P2&
0X80);
voidWrite_com(ucharcom)
Check_Busy();
RW=0;
P2=com;
delay
(1);
EN=0;
voidWrite_dat(uchardat)
RS=1;
P2=dat;
voidLcd_Pos(ucharXpos,ucharYpos)
{
uchartmp;
Xpos&
=0x0f;
Ypos&
=0x03;
tmp=Xpos;
if(Ypos==0)
tmp|=0x80;
if(Ypos==1)
tmp|=0x90;
if(Ypos==2)
tmp|=0x88;
if(Ypos==3)
tmp|=0x98;
Write_com(tmp);
voidWrite_LCD_String(ucharx,uchary,uchar*s)
Lcd_Pos(x,y);
while(*s!
='
\0'
)
{
Write_dat(*s);
s++;
voidLCD_Rst(void)
Write_com(0x30);
Write_com(0x01);
Write_com(0x06);
Write_com(0x0c);
delay(5);
voidWrite_day(ucharSel)
switch(Sel)
case1:
Write_LCD_String(6,1,"
一"
);
break;
case2:
二"
case3:
Lcd_Pos(6,1);
Write_dat(0xc8);
Write_dat(0xfd);
case4:
四"
case5:
五"
case6:
六"
case7:
日"
default:
voidUpdat_Time(void)
Lcd_Pos(3,0);
Write_dat(0x30+(year/10));
Write_dat(0x30+(year%10));
Lcd_Pos(0,1);
Write_dat(0x30+(mon/10));
Write_dat(0x30+(mon%10));
Lcd_Pos(2,1);
Write_dat(0x30+(date/10));
Write_dat(0x30+(date%10));
Lcd_Pos(0,2);
Write_dat(0x30+(hour/10));
Write_dat(0x30+(hour%10));
Lcd_Pos(2,2);
Write_dat(0x30+(min/10));
Write_dat(0x30+(min%10));
Lcd_Pos(4,2);
Write_dat(0x30+(sec/10));
Write_dat(0x30+(sec%10));
Write_day(day);
voidWrite_Time(void)
Write_Ds1302(0x8e,0x00);
Write_Ds1302(0x8c,(year/10)*16+year%10);
Write_Ds1302(0x88,(mon/10)*16+mon%10);
Write_Ds1302(0x86,(date/10)*16+date%10);
Write_Ds1302(0x84,(hour/10)*16+hour%10);
Write_Ds1302(0x82,(min/10)*16+min%10);
Write_Ds1302(0x80,(sec/10)*16+sec%10);
Write_Ds1302(0x8a,(day/10)*16+day%10);
Write_Ds1302(0x8e,0x80);
voidRead_Time(void)
year=(Read_Ds1302(0x8d)>
4)*10+Read_Ds1302(0x8d)%16;
mon=(Read_Ds1302(0x89)>
4)*10+Read_Ds1302(0x89)%16;
date=(Read_Ds1302(0x87)>
4)*10+Read_Ds1302(0x87)%16;
hour=(Read_Ds1302(0x85)>
4)*10+Read_Ds1302(0x85)%16;
min=(Read_Ds1302(0x83)>
4)*10+Read_Ds1302(0x83)%16;
sec=(Read_Ds1302(0x81)>
4)*10+Read_Ds1302(0x81)%16;
day=(Read_Ds1302(0x8b)>
4)*10+Read_Ds1302(0x8b)%16;
Updat_Time();
}
voidSet_Time(void)
if(FUN==0)
delay(10);
while(!
FUN);
flag=1;
num++;
if(num==8)
num=1;
if(flag)
if(num==1)
Write_com(0x0d);
if(INC==0)
if(INC==0)
INC);
hour++;
if(hour==24)
hour=0;
if(DEC==0)
if(DEC==0)
DEC);
hour--;
if(hour==-1)
hour=23;
}
if(num==2)
min++;
if(min==60)
min=0;
min--;
if(min==-1)
min=59;
if(num==3)
Write_com(0x0d);
sec++;
if(sec==60)
sec=0;
sec--;
if(sec==-1)
sec=59;
if(num==4)
year++;
if(year==100)
year=0;
year--;
if(year==-1)
sec=99;
if(num==5)
Lcd_Pos(0,1);
mon++;
if(mon==13)
mon=1;
mon--;
if(mon==0)
mon=12;
if(num==6)
Lcd_Pos(2,1);
date++;
if(date==32)
date=1;
date--;
if(date==0)
date=31;
if(num==7)
day++;
if(day==8)
day=1;
day--;
if(day==0)
day=7;
i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 万年历 初始 源程序