|
普中V2.0板子 ,設(shè)置上限報警值,數(shù)碼管顯示溫度
# include<reg52.h>
# define uchar unsigned char
# define uint unsigned int
sbit ds=P3^7;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
sbit beep=P1^5;
sbit ina=P2^0;
sbit inb=P2^1;
uchar low=10;
uchar high=31;
Displaydat[6];
uint code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void Delayus(uchar t)
{
while(t--);
}
void be(int temp)
{ uchar i;
if(temp>(high*100))
{ for(i=0;i<120;i++)
{ Delayus(60);
beep=~beep;
}
} else
{ beep=0;
}
}
void Datpros(int temp)
{ float tp;
if(temp<0)
{Displaydat[0]=0x40;
temp=temp-1;
temp=~temp;
tp=temp;
temp=tp*0.0625*100+0.5;
}
else
{
Displaydat[0]=0x00;
tp=temp;
temp=tp*0.0625*100+0.5 ;
}
Displaydat[1]=smgduan[temp/10000];
Displaydat[2]=smgduan[temp%10000/1000];
Displaydat[3]=smgduan[temp%1000/100]|0x80;
Displaydat[4]=smgduan[temp%100/10];
Displaydat[5]=smgduan[temp%10];
be(temp);
}
void Dispaly()
{ uchar i;
for(i=0;i<6;i++)
{switch(i)
{ case(0):
LSA=0;LSB=0;LSC=0; break;//?????0λ
case(1):
LSA=1;LSB=0;LSC=0; break;//?????1λ
case(2):
LSA=0;LSB=1;LSC=0; break;//?????2λ
case(3):
LSA=1;LSB=1;LSC=0; break;//?????3λ
case(4):
LSA=0;LSB=0;LSC=1; break;//?????4λ
case(5):
LSA=1;LSB=0;LSC=1; break;//?????5λ
}
P0=Displaydat[5-i];
Delayus(200);
P0=0x00;}
}
uchar Ds18b20_init()
{ uchar i;
ds=0;
Delayus(70);
ds=1;
i=0;
while(ds)
{ Delayus(20);
i++;
if(i>5)
{ return 0;}
}
return 1;
}
void Writebyte(uchar dat)
{ uchar i;
for(i=0;i<8;i++)
{ ds=0;
Delayus(1);
ds=dat&0x01;
Delayus(8);
ds=1;
dat>>=1; }
}
uchar Readbyte()
{ uchar i,bi,byte;
for(i=0;i<8;i++)
{ ds=0;
ds=1;
Delayus(1);
bi=ds;
byte=(byte>>1)|(bi<<7);
Delayus(6); }
return byte;
}
void Changetemp()
{ Ds18b20_init();
Delayus(100);
Writebyte(0xcc);
Writebyte(0x44);
Delayus(10);
Ds18b20_init();
Delayus(100);
Writebyte(0xcc);
Writebyte(0xbe);
}
int Readtemp()
{ uchar tml,tmh;
int temp=0;
Changetemp();
tml=Readbyte();
tmh=Readbyte();
temp=tmh;
temp<<=8;
temp|=tml;
return temp;
}
void main()
{ while(1)
{Datpros(Readtemp());
Dispaly();
}
}
|
-
-
實驗2:wd.zip
2019-5-27 11:38 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
27.64 KB, 下載次數(shù): 19, 下載積分: 黑幣 -5
|