主要實現(xiàn):
? ? 實時溫度測量及顯示,超出溫度范圍聲光報警,上下限溫度可通過按鍵設(shè)定等功能。 本數(shù)字溫度報警器是基于51單片機及溫度傳感器DS18B20來設(shè)計的,溫度測量范圍-55到125.9攝氏度,精度為0.1攝氏度,可見測量溫度的范圍廣,精度高的特點??赏ㄟ^按鍵設(shè)置上下限報警溫度值,報警設(shè)置范圍0~99攝氏度,默認(rèn)上限報警溫度為40℃、默認(rèn)下限報警溫度為10℃(通過程序可以更改上下限值)。報警值可設(shè)置范圍:最低上限報警值等于當(dāng)前下限報警值,最高下限報警值等于當(dāng)前上限報警值。
uint ReadTemperature();
void convdata();
void xianshi();
void sound();
void czhi();
void sdong();
void show();
void restzhi();
void datadisp();//
void jingque();
sbit SD=P0^0;
sbit SET=P0^1;
sbit Jian=P0^2;
sbit Jia=P0^3;
sbit Md=P0^4;
sbit p05=P0^5;
sbit p06=P0^6;
sbit p07=P0^7;
sbit CS=P3^0;
sbit Clk=P3^1;
sbit DATI=P3^2;
sbit DATO=P3^2;
sbit DQ=P3^3;
sbit Ledzc=P3^4;
sbit Ledrbj=P3^5;
sbit Ledybj=P3^6;
sbit Fmbj=P3^7;
uchar led_mod[]
=
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xBF,
0xff};
uchar led_com[]={0x08,0x04,0x02,0x01,0x00};
uchar tg=0;tflag;//
unsigned char dat0=0x00;
unsigned char CH=0x00;
unsigned char dis[]={0, 0, 0};
uchar disdata[]={0,10,0,0,0,0};
uchar shezhi[]={0,0,0,0};
uchar jque[]={0,0,0,0,0};
int sign=0,js,qo,temp,ywu,ybz;
int Time=65000; //
int pbi=500,ts=0,ys=0,is=0,ll;
uint tuxian=30,yuxian=3,temp0;
void Delay(uint i)
{
while( i-- );
}
void delayt(uint time)
{
int j;
for(;time>0;time--)
for(j=0;j<100;j++);
}
void Init_DS18B20(void)
{
uint x=0;
DQ=1;
Delay(10);
DQ=0;
Delay(80);
DQ=1;
Delay(10);
x=DQ;
Delay(20);
}
unsigned char ReadOneChar(void)
{
uint i=0;
uint dat=0;
for (i=8;i>0;i--)
{
DQ=0;
dat>>=1;
DQ=1;
if(DQ);//
dat|=0x80;
Delay(4);
}
return(dat);
}
void WriteOneChar(uint dat)
{
uint i=0;
for (i=8; i>0; i--)
{
DQ=0;
DQ=dat&0x01;
Delay(5);
DQ=1;
dat>>=1;
}
}
void Tmpchange(void)
{
Init_DS18B20();
WriteOneChar(0xCC);
WriteOneChar(0x44);
}
uint ReadTemperature(void)
{
uint a=0;
uint b=0;
uint t=0;
float tt=0;
Tmpchange();
Init_DS18B20();
WriteOneChar(0xCC);
WriteOneChar(0xBE);
a=ReadOneChar();
b=ReadOneChar();
t=b;
t<<=8;
t=t|a;
if(t<0x0fff)
tflag=0;
else
{t=~t+1;
tflag=1;
}
t=t*(0.0625*10);
return(t);
}
unsigned char adc0832(unsigned char CH)
{
unsigned char i,test,adval;
adval=0x00;
test=0x00;
Clk=0;
DATI=1;
_nop_();
CS=0;
_nop_();
Clk=1;
_nop_();
if ( CH==0x00 )
{
Clk=0;
DATI=1;
_nop_();
Clk=1;
_nop_();
Clk=0;
DATI=0;
_nop_();
Clk=1;
_nop_();
}
else
{
Clk=0;
DATI=1;
_nop_();
Clk=1;
_nop_();
Clk=0;
DATI=1;
_nop_();
Clk=1;
_nop_();
}
Clk=0;
DATI=1;
for( i=0;i < 8;i++ )
{
_nop_();
adval <<=1;
Clk=1;
_nop_();
Clk=0;
if (DATO)
adval |=0x01;
else
adval |=0x00;
}
for (i=0; i < 8; i++)
{
test >>=1;
if (DATO)
test |=0x80;
else
test |=0x00;
_nop_();
Clk=1;
_nop_();
Clk=0;
}
dat0=test;
_nop_();
CS=1;
DATO=1;
Clk=1;
return dat0;
資料借鑒于此紛傳