赞
踩
主要实现:
实时温度测量及显示,超出温度范围声光报警,上下限温度可通过按键设定等功能。 本数字温度报警器是基于51单片机及温度传感器DS18B20来设计的,温度测量范围-55到125.9摄氏度,精度为0.1摄氏度,可见测量温度的范围广,精度高的特点。可通过按键设置上下限报警温度值,报警设置范围0~99摄氏度,默认上限报警温度为40℃、默认下限报警温度为10℃(通过程序可以更改上下限值)。报警值可设置范围:最低上限报警值等于当前下限报警值,最高下限报警值等于当前上限报警值。
- 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;
资料借鉴于此纷传
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。