整理时间温度日历.docx

上传人:b****8 文档编号:9429738 上传时间:2023-02-04 格式:DOCX 页数:27 大小:20.80KB
下载 相关 举报
整理时间温度日历.docx_第1页
第1页 / 共27页
整理时间温度日历.docx_第2页
第2页 / 共27页
整理时间温度日历.docx_第3页
第3页 / 共27页
整理时间温度日历.docx_第4页
第4页 / 共27页
整理时间温度日历.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

整理时间温度日历.docx

《整理时间温度日历.docx》由会员分享,可在线阅读,更多相关《整理时间温度日历.docx(27页珍藏版)》请在冰豆网上搜索。

整理时间温度日历.docx

整理时间温度日历

/*52单片机与ds12b887,ds18b20综合使用,1602显示*/

#include

#include

#defineucharunsignedchar

#defineuintunsignedint

sbitdula=P2^6;

sbitwela=P2^7;

sbitrs=P3^5;

sbitwr=P3^6;

sbitE=P3^4;

sbits1=P3^0;

sbits2=P3^1;

sbits3=P3^2;

sbits4=P3^2;//闹钟查看键

sbitrd=P3^7;

sbitbeep=P2^3;

sbitdscs=P1^4;

sbitdsas=P1^5;

sbitdswr=P1^6;

sbitdsds=P1^7;

sbitdsirq=P3^3;

sbitJD=P0^6;

sbitBF=P0^7;

sbitDQ=P2^2;

bitflag1,flag_ri;

ucharcount,s1num,flag,t0_num;

ucharmiao,shi,fen,year,month,day,week,amiao,afen,ashi,time;

voidwrite_ds(uchar,uchar);//函数申明

voidset_alarm(uchar,uchar,uchar);voidread_alarm();

ucharread_ds(uchar);voidset_time();

ucharcodetable[]="20--";

ucharcodetable1[]=":

:

";

ucharcodedigit[10]={"0123456789"};

ucharcodeError[]={"Error!

Check!

"};

ucharcodeTemp[]={"Temp:

"};

ucharcodeCent[]={"*C"};

ucharread_ds(ucharadd)

{

uchards_date;

dsas=1;

dsds=1;

dswr=1;

dscs=0;

P0=add;

dsas=0;

dsds=0;

P0=0xff;

ds_date=P0;

dsds=1;

dsas=1;

dscs=1;

returnds_date;

}

voidwrite_ds(ucharadd,uchardate)

{

dscs=0;

dsas=1;

dsds=1;

dswr=1;

P0=add;

dsas=0;

dswr=0;

P0=date;

dswr=1;

dsas=1;

dscs=1;

}

voidset_time()

{

write_ds(4,10);

write_ds(2,32);

}

voidset_alarm(ucharashi,ucharafen,ucharamiao)

{

write_ds(1,amiao);

write_ds(3,afen);

write_ds(5,ashi);

}

voiddelay(uintz)

{

uintx,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

voiddelay1ms()

{

unsignedchari,j;

for(i=0;i<4;i++)

for(j=0;j<33;j++)

;

}

voiddelaynms(unsignedcharn)

{

unsignedchari;

for(i=0;i

delay1ms();

}

voiddi()

{

beep=0;

delay(100);

beep=1;

}

voiddidi()

{

beep=0;

delay(50);

beep=1;

delay(100);

beep=0;

delay(50);

beep=1;

}

voidwrite_com(ucharcom)

{

rs=0;

E=0;

P0=com;

delay(5);

E=1;

delay(5);

E=0;

}

voidwrite_date(uchardate)

{

rs=1;

E=0;

P0=date;

delay(5);

E=1;

delay(5);

E=0;

}

voidinit()

{

ucharnum;

EA=1;

EX1=1;

IT1=1;

flag1=0;

t0_num=0;

s1num=0;

week=1;

dula=0;

wela=0;

E=0;

rd=0;

//以下几行在首次设置DS12C887时使用,以后不必再写入

write_ds(0x0A,0x20);

write_ds(0x0B,0x26);//设置24小时模式,数据二进制格式

set_time();//设置上电默认时间

//-----------------------------------------------------*/

write_com(0x38);//1602液晶初始化

write_com(0x0c);

write_com(0x06);

write_com(0x01);

write_com(0x80);

for(num=0;num<15;num++)//写入液晶固定部分显示

{

write_date(table[num]);

delay

(1);

}

write_com(0x80+0x40);

for(num=0;num<11;num++)

{

write_date(table1[num]);

delay

(1);

}

}

voidwrite_sfm(ucharadd,uchardate)

{

ucharshi,ge;

shi=date/10;

ge=date%10;

write_com(0x80+0x40+add);

write_date(0x30+shi);

write_date(0x30+ge);

}

bitBusyTest(void)

{

bitresult;

rs=0;

wr=1;

E=1;

_nop_();

_nop_();

_nop_();

_nop_();

result=BF;

E=0;

returnresult;

}

voidWriteInstruction(unsignedchardictate)

{

while(BusyTest()==1);

rs=0;

wr=0;

E=0;

_nop_();

_nop_();

P0=dictate;

_nop_();

_nop_();

_nop_();

_nop_();

E=1;

_nop_();

_nop_();

_nop_();

_nop_();

E=0;

}

voidWriteAddress(unsignedcharx)

{

WriteInstruction(x|0x80);

}

voidWriteData(unsignedchary)

{

while(BusyTest()==1);

rs=1;

wr=0;

E=0;

P0=y;

_nop_();

_nop_();

_nop_();

_nop_();

E=1;

_nop_();

_nop_();

_nop_();

_nop_();

E=0;

}

voidLcdInitiate(void)

{

delaynms(15);

WriteInstruction(0x38);

delaynms(5);

WriteInstruction(0x38);

delaynms(5);

WriteInstruction(0x38);

delaynms(5);

WriteInstruction(0x0c);

delaynms(5);

WriteInstruction(0x06);

delaynms(5);

WriteInstruction(0x01);

delaynms(5);

}

bitInit_DS18B20(void)

{

bitflag;

DQ=1;

for(time=0;time<2;time++);

DQ=0;

for(time=0;time<200;time++);

DQ=1;

for(time=0;time<10;time++);

flag=DQ;

for(time=0;time<200;time++);

return(flag);

}

ucharReadOneChar(void)

{

unsignedchari=0;

unsignedchardat;

for(i=0;i<8;i++)

{

DQ=1;

_nop_();

DQ=0;

dat>>=1;

_nop_();

DQ=1;

for(time=0;time<2;time++)

;

if(DQ==1)

dat|=0x80;

else

dat|=0x00;

for(time=0;time<8;time++);

}

return(dat);

}

WriteOneChar(unsignedchardat)

{

unsignedchari=0;

for(i=0;i<8;i++)

{

DQ=1;

_nop_();

DQ=0;

DQ=dat&0x01;

for(time=0;time<10;time++);

DQ=1;

for(time=0;time<1;time++);

dat>>=1;

}

for(time=0;time<4;time++);

}

voiddisplay_error(void)

{

unsignedchari;

WriteAddress(0x00);

i=0;

while(Error[i]!

='\0')

{

WriteData(Error[i]);

i++;

delaynms(100);

}

while

(1)

;

}

voiddisplay_dot(void)

{

WriteAddress(0x4c);

WriteData('.');

delaynms(50);

}

voiddisplay_cent(void)

{

unsignedchari;

WriteAddress(0x4e);

i=0;

while(Cent[i]!

='\0')

{

WriteData(Cent[i]);

i++;

delaynms(50);

}

}

voiddisplay_temp1(unsignedcharx)

{

unsignedcharj,k,l;

j=x/100;

k=(x%100)/10;

l=x%10;

WriteAddress(0x4a);

WriteData(digit[k]);

WriteData(digit[l]);

delaynms(50);

}

voiddisplay_temp2(unsignedcharx)

{

WriteAddress(0x4d);

WriteData(digit[x]);

delaynms(50);

}

voidReadyReadTemp(void)

{

Init_DS18B20();

WriteOneChar(0xCC);

WriteOneChar(0x44);

for(time=0;time<100;time++);

Init_DS18B20();

WriteOneChar(0xCC);

WriteOneChar(0xBE);

}

voidwrite_nyr(ucharadd,chardate)

{//1602液晶刷新年月日函数3为年,6为分,9为秒

charshi,ge;

shi=date/10;

ge=date%10;

write_com(0x80+add);

write_date(0x30+shi);

write_date(0x30+ge);

}

voidwrite_week(charwe)

{//写液晶星期显示函数

write_com(0x80+12);

switch(we)

{

case1:

write_date('M');delay(5);

write_date('O');delay(5);

write_date('N');

break;

case2:

write_date('T');delay(5);

write_date('U');delay(5);

write_date('E');

break;

case3:

write_date('W');delay(5);

write_date('E');delay(5);

write_date('D');

break;

case4:

write_date('T');delay(5);

write_date('H');delay(5);

write_date('U');

break;

case5:

write_date('F');delay(5);

write_date('R');delay(5);

write_date('I');

break;

case6:

write_date('S');delay(5);

write_date('A');delay(5);

write_date('T');

break;

case7:

write_date('S');delay(5);

write_date('U');delay(5);

write_date('N');

break;

}

}

voidkeyscan()

{

if(flag_ri==1)

{

if((s1==0)||(s2==0)||(s3==0)||(s4==0))

{

delay(5);

if((s1==0)||(s2==0)||(s3==0)||(s4==0))

{

while(!

(s1&&s2&&s3&&s4));

di();

flag_ri=0;

}

}

}

if(s1==0)

{

delay(5);

if(s1==0)

{

s1num++;

if(flag1==1)

if(s1num==4)

s1num=1;

flag=1;

while(!

s1);di();

switch(s1num)

{

case1:

write_com(0x80+0x40+6);

write_com(0x0f);

break;

case2:

write_com(0x80+0x40+3);

break;

case3:

write_com(0x80+0x40+0);

break;

case4:

write_com(0x80+12);

break;

case5:

write_com(0x80+9);

break;

case6:

write_com(0x80+6);

break;

case7:

write_com(0x80+3);

break;

case8:

s1num=0;

write_com(0x0c);

flag=0;

write_ds(0,miao);

write_ds(2,fen);

write_ds(4,shi);

write_ds(6,week);

write_ds(7,day);

write_ds(8,month);

write_ds(9,year);

break;

}

}

}

if(s1num!

=0)

{

if(s2==0)

{

delay

(1);

if(s2==0)

{

while(!

s2);di();

switch(s1num)

{

case1:

miao++;

if(miao==60)

miao=0;

write_sfm(10,miao);

write_com(0x80+0x40+6);

break;

case2:

fen++;

if(fen==60)

fen=0;

write_sfm(7,fen);

write_com(0x80+0x40+3);

break;

case3:

shi++;

if(shi==24)

shi=0;

write_sfm(4,shi);

write_com(0x80+0x40+0);

break;

case4:

week++;

if(week==8)

week=1;

write_week(week);

write_com(0x80+12);

break;

case5:

day++;

if(day==32)

day=1;

write_nyr(9,day);

write_com(0x80+9);

break;

case6:

month++;

if(month==13)

month=1;

write_nyr(6,month);

write_com(0x80+6);

break;

case7:

year++;

if(year==100)

year=0;

write_nyr(3,year);

write_com(0x80+3);

break;

}

}

}

if(s3==0)

{

delay

(1);

if(s3==0)

{

while(!

s3);di();

switch(s1num)

{

case1:

miao--;

if(miao==-1)

miao=59;

write_sfm(6,miao);

write_com(0x80+0x40+6);

break;

case2:

fen--;

if(fen==-1)

fen=59;

write_sfm(3,fen);

write_com(0x80+0x40+3);

break;

case3:

shi--;

if(shi==-1)

shi=23;

write_sfm(0,shi);

write_com(0x80+0x40+0);

break;

case4:

week--;

if(week==0)

week=7;

write_week(week);

write_com(0x80+12);

break;

case5:

day--;

if(day==0)

day=31;

write_nyr(9,day);

write_com(0x80+9);

break;

case6:

month--;

if(month==0)

month=12;

write_nyr(6,month);

write_com(0x80+6);

break;

case7:

year--;

if(year==-1)

year=99;

write_nyr(3,year);

write_com(0x80+3);

break;

}

}

}

}

if(s4==0)

{

delay(5);

if(s4==0)

{

flag1=~flag1;

while(!

s4);di();

if(flag1==0)

{

flag=0;

write_com(0x80+0x40);

write_date('');

write_date('');

write_com(0x0c);

write_ds(1,miao);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 科学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1