uint Readtemp()
{
uchar a=0;
uchar b=0;
uint t=0;
float tt=0;
Init_DS18B20();
WriteOneChar(0xCC); //跳過(guò)讀序號(hào)列號(hào)的操作
WriteOneChar(0x44); //啟動(dòng)溫度轉(zhuǎn)換
Init_DS18B20();
WriteOneChar(0xCC); //跳過(guò)讀序號(hào)列號(hào)的操作
WriteOneChar(0xBE); //讀取溫度寄存器
a=ReadOneChar(); //讀低8位
b=ReadOneChar(); //讀高8位
t=b;
t<<=8;
t=t|a;
tt=t*0.0625;
t= tt*10+0.5; //放大10倍輸出并四舍五入
return(t);
}
void display(uint temp)
{
uchar A1,A2,A3;
A1=temp/100;
A2=temp%100/10;
A3=temp%10;
write_com(0x80+0x40+10);
write_date(0x30+A1);//十位
write_date(0x30+A2);//個(gè)位
write_date(0x2e);//小數(shù)點(diǎn)
write_date(0x30+A3);//小數(shù)點(diǎn)后一位
write_date(0xdf);//
write_date(0x43);//C本文引用地址:http://m.butianyuan.cn/article/201611/321018.htm}
void didi()
{
beep=0;
delay(100);
beep=1;
}
void write_nyrx(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_sfm(uchar add,uchar date)//
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void keyscan()
{
//rd=0;
if(flag1==1)//按s1 s4鍵消除報(bào)警
{
if((s1==0)||(s4==0))
{
delay(5);
if((s1==0)||(s4==0))
while(!(s1&&s4));
didi();
flag1=0;//消除報(bào)警標(biāo)志
}
}
if(s1==0)//調(diào)時(shí)功能鍵
{
delay(5);
if(s1==0)
{
s1num++;
flag=1;//flag功能鍵標(biāo)志位 0為顯示,1為不顯示
while(!s1);
didi();
if(s1num==1)
{
TR1=0;
write_com(0x80+0x40+8);
write_com(0x0f);
}
if(s1num==2)
{
write_com(0x80+0x40+5);
}
if(s1num==3)
{
write_com(0x80+0x40+2);
}
if(s1num==4)
{
write_com(0x80+9);
}
if(s1num==5)
{
write_com(0x80+6);
}
if(s1num==6)
{
write_com(0x80+3);
}
if(s1num==7)
{
write_com(0x80+0);
}
if(s1num==8)
{
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,ri);
write_ds(8,yue);
write_ds(9,nian);
}
}
}
if(s1num!=0)
{
if(s2==0)//功能鍵加1
{
delay(5);
if(s2==0)
{
delay(5);
while(!s2);
didi();
if(s1num==1)
{
miao++;
if(miao==60)
miao=0;
write_sfm(7,miao);
write_com(0x80+0x40+8);
}
if(s1num==2)
{
fen++;
if(fen==60)
fen=0;
write_sfm(4,fen);
write_com(0x80+0x40+5);
}
if(s1num==3)
{
shi++;
if(shi==24)
shi=0;
write_sfm(1,shi);
write_com(0x80+0x40+2);
}
if(s1num==4)
{
week++;
if(week==8)
week=0;
write_com(0x80+9);
write_date(table3[week]);
write_date(table4[week]);
write_date(table5[week]);
}
if(s1num==5)
{
ri++;
if(ri==32)
ri=1;
write_nyrx(6,ri);
write_com(0x80+6);
}
if(s1num==6)
{
yue++;
if(yue==13)
yue=1;
write_nyrx(3,yue);
write_com(0x80+3);
}
if(s1num==7)
{
nian++;
if(nian==99)
nian=0;
write_nyrx(0,nian);
write_com(0x80+0);
}
}
}
if(s3==0)//功能鍵減1
{
delay(5);
if(s3==0)
{
delay(5);
while(!s3);
didi();
if(s1num==1)
{
miao--;
if(miao==-1)
miao=59;
write_sfm(7,miao);
write_com(0x80+0x40+8);
}
if(s1num==2)
{
fen--;
if(fen==-1)
fen=59;
write_sfm(4,fen);
write_com(0x80+0x40+5);
}
if(s1num==3)
{
shi--;
if(shi==-1)
shi=23;
write_sfm(1,shi);
write_com(0x80+0x40+2);
}
if(s1num==4)
{
week--;
if(week==0)
week=7;
write_com(0x80+9);
write_date(table3[week]);
write_date(table4[week]);
write_date(table5[week]);
}
if(s1num==5)
{
ri--;
if(ri==0)
ri=31;
write_nyrx(6,ri);
write_com(0x80+6);
}
if(s1num==6)
{
yue--;
if(yue==0)
yue=12;
write_nyrx(3,yue);
write_com(0x80+3);
}
if(s1num==7)
{
nian--;
if(nian==-1)
nian=99;
write_nyrx(0,nian);
write_com(0x80+0);
}
}
}
}
評(píng)論