
/ writer:shoppingw /
#include <reg51h>
#include <intrinsh>
#define uint unsigned int
#define uchar unsigned char
sbit DQ = P3^6;
uchar code DSY_CODE[] =
{ 0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0X00};
uchar code df_Table[] = {0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9};
uchar CurrentT = 0;
uchar Temp_Value[]={0x11,0x22};
uchar Display_Digit[]={0,0,0,0};
bit DS18B20_IS_OK = 1;
void Delay(uint x)
{
while(--x);
}
uchar Init_DS18B20()
{
uchar status;
DQ = 1;
Delay(8);
DQ = 0;
Delay(90);
DQ = 1;
Delay(8);
DQ = 1;
return status;
}
uchar ReadOneByte()
{
uchar i,dat=0;
DQ = 1;
_nop_();
for(i=0;i<8;i++)
{
DQ = 0;
dat >>= 1;
DQ = 1;
_nop_();
_nop_();
if(DQ)
dat |= 0X80;
Delay(30);
DQ = 1;
}
return dat;
}
void WriteOneByte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
DQ = 0;
DQ = dat& 0x01;
Delay(5);
DQ = 1;
dat >>= 1;
}
}
void Read_Temperature()
{
if(Init_DS18B20() ==1 )
DS18B20_IS_OK = 0;
else
{
WriteOneByte(0xcc);
WriteOneByte(0x44);
Init_DS18B20();
WriteOneByte(0xcc);
WriteOneByte(0xbe);
Temp_Value[0] = ReadOneByte();
Temp_Value[1] = ReadOneByte();
DS18B20_IS_OK=1;
}
}
void Display_Temperature()
{
uchar i;
uchar t=150;
uchar ng=0, np=0;
if ( (Temp_Value[1] & 0xf8) == 0xf8)
{
Temp_Value[1] = ~Temp_Value[1];
Temp_Value[0] = ~Temp_Value[0]+1;
if (Temp_Value[0] == 0x00) Temp_Value[1]++;
ng=1;np=0xfd;
}
Display_Digit[0] = df_Table[ Temp_Value[0] & 0x0f ];
CurrentT = ((Temp_Value[0] & 0xf0)>>4) | ((Temp_Value[1] & 0x07)<<4);
Display_Digit[3] = CurrentT / 100;
Display_Digit[2] = CurrentT % 100 / 10;
Display_Digit[1] = CurrentT % 10;
if (Display_Digit[3] == 0)
{
Display_Digit[3] = 10;
np = 0xfb;
if (Display_Digit[2] == 0)
{
Display_Digit[2] = 10;
np = 0xf7;
}
}
for (i=0;i<30;i++)
{
P0=0x39;P2=0x7f;Delay(t);P2=0xFF;
P0=0x63;P2=0xbf;Delay(t);P2=0xff;
P0=DSY_CODE[Display_Digit[0]];
P2=0xDF;Delay(t);P2=0xff;
P0=(DSY_CODE[Display_Digit[1]]) | 0x80;
P2=0xef;Delay(t);P2=0xff;
P0=DSY_CODE[Display_Digit[2]];
P2=0xf7;Delay(t);P2=0xff;
P0=DSY_CODE[Display_Digit[3]];
P2=0xfb; Delay(t); P2=0xff;
if (ng)
{
P0 = 0x40; P2 = np; Delay(t); P2=0xff;
}
}
}
void main()
{
Read_Temperature();
Delay(50000);
Delay(50000);
while(1)
{
Read_Temperature();
if(DS18B20_IS_OK)
Display_Temperature();
}
}
一、意义
这种温度采集系统便于和电脑连接,利用网络可做成远程系统。
二、研究内容
1、温度采集传感器的原理及选型,如采用铂电阻还是热电偶;
2、传感器信号的处理;
3、微处理器或DSP应用技术;
4、USB芯片的使用,主要指编写下位机通信程序。
三、研究方法
1、找一本基础的书,先学习基础知识;
2、如身边有高手,请教,这样来得快;
3、上网查找资料,这种东西或许网上就有现成的电路或程序。
四、USB主机
USB是连接PC与外围设各的接口。估计你关心的还是USB控制器,即你要完成的控制系统的USB控制芯片。你的系统要和上位机(即微机)进行通讯,你的系统里肯定得有一块USB控制芯片,或者具有USB接口功能的微处理器。
基本上是:风机,压缩机的控制。启停的标准是设定温度与外界实际温度的比较结果。你这个如果不做出东西的话,程序应该很简单,要出实际控制电路版的话需要外围的一些传感器驱动程序,加上就可以了
以上就是关于单片机温度检测的程序全部的内容,包括:单片机温度检测的程序、电脑温度监控软件(电脑温度监控软件哪个准)、c语言的单片机控制的空调温度控制系统的源程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)