| 加入桌面 | 手机?/a> | 无图?/a>
 
当前位置: 首页 » 知识 » 数据采集器 » 正文

单片机课程设计-单总线温度采集器设计

已解决 悬赏分:20 - 解决时间 2008-07-08 17:34
1、以单片机为主控器,采用单总线温度传感器DS18B20设计一个温度采集装置。 2、测温范围为10~50℃ 3、误差在0.1℃以内 4、具有温度显示功能
72 次关注     提问者: 问问我问问我  
  支持(0)  |   反对(0) 最佳答案
这个是我自己制作的51单片机板上的DS18B20温度采集和显示程序,你如果有现成的51板稍微修改一下可以用,在我这里是可以用没问题的。环境是KEIL。我这个51板也完全符合你的要求。#pragmadbcode#include<AT89X52.H>//#include"reg52.h"#include"INTRINS.H"//此实验是使用18B20检测温度,然后在数码管上显示#defineucharunsignedchar#defineuintunsignedint#defineBUSY1(DQ1==0)sbitLED_0=P1^0;sbitLED_1=P1^1;sbitLED_2=P1^2;sbitLED_3=P1^3;sbitDQ1=P1^6;//voiddelay(uintx);voiddisplay(unsignedchard1,unsignedchard2,unsignedchard3,unsignedchard4);voidds_reset_1(void);voidwr_ds18_1(chardat);voidtime_delay(unsignedchartime);intget_temp_1(void);voiddelay(unsignedintx);voidread_ROM(void);intget_temp_d(void);/*=====0-9=====A-G=====*/uchara[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0x86,0x8e,0x82};unsignedcharResultSignal;intResultTemperatureLH,ResultTemperatureLL,ResultTemperatureH;unsignedcharROM[8];unsignedcharidataTMP;unsignedcharidataTMP_d;unsignedcharf;unsignedcharrd_ds18_1();unsignedintTemH,TemL;voidmain(){unsignedintTemH,TemL,k=0;ds_reset_1();ds_reset_1();//resetwr_ds18_1(0xcc);//skiprom_nop_();wr_ds18_1(0x7f);ds_reset_1();wr_ds18_1(0xcc);_nop_();wr_ds18_1(0x44);for(k=0;k<11000;k++)time_delay(255);ds_reset_1();while(1){wr_ds18_1(0xcc);wr_ds18_1(0xbe);TemH=get_temp_1();TemL=get_temp_d();TemH&=0x00ff;TemL&=0x00ff;display((TemH/10),(TemH%10),(TemL/10),(TemL%10));}}/***************延时程序,单位us,大于10us*************/voidtime_delay(unsignedchartime){time=time-10;time=time/6;while(time!=0)time--;}/*****************************************************//*resetds18b20*//*****************************************************/voidds_reset_1(void){unsignedcharidatacount=0;DQ1=0;time_delay(240);time_delay(240);DQ1=1;return;}voidcheck_pre_1(void){while(DQ1);while(~DQ1);time_delay(30);}voidread_ROM(void){intn;ds_reset_1();check_pre_1();wr_ds18_1(0x33);for(n=0;n<8;n++){ROM[n]=rd_ds18_1();}}/*****************************************************//*Readabitfrom1820位读取*//*****************************************************/bittmrbit_1(void){idatachari=0;bitdat;DQ1=0;_nop_();DQ1=1;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();dat=DQ1;time_delay(50);returndat;}/*****************************************************//*readabetyfromds18b20字节读取*//*****************************************************/unsignedcharrd_ds18_1(){unsignedcharidatai,j,dat=0;for(i=1;i<=8;i++){j=tmrbit_1();dat=(j<<(i-1))|dat;}returndat;}/*****************************************************//*writeabetyfromds18b20写字节*//****************************************************/voidwr_ds18_1(chardat){signedcharidatai=0;unsignedcharidataj;bittestb;for(j=1;j<=8;j++){testb=dat&0x01;dat=dat>>1;if(testb){DQ1=0;_nop_();_nop_();DQ1=1;time_delay(60);}else{DQ1=0;time_delay(50);DQ1=1;_nop_();_nop_();}}}intget_temp_1(void){unsignedcharidataa=0,b=0;unsignedcharidatai;EA=0;ds_reset_1();check_pre_1();wr_ds18_1(0xcc);wr_ds18_1(0x44);while(BUSY1);ds_reset_1();check_pre_1();wr_ds18_1(0xcc);wr_ds18_1(0xbe);a=rd_ds18_1();b=rd_ds18_1();i=b;/*若b为1则为负温*/i=(i>>4);if(i==0){f=0;TMP=((a>>4)|(b<<4));a=(a&0x0f);if(a>8){TMP=(TMP+1);}}else{f=1;a=a>>4;b=b<<4;TMP=(a|b);TMP=~TMP;TMP=(TMP+1);}EA=1;return(TMP);}intget_temp_d(void){unsignedcharidataa=0,b=0;unsignedcharidatai,m;EA=0;ds_reset_1();//复位check_pre_1();wr_ds18_1(0xcc);wr_ds18_1(0x44);while(BUSY1);ds_reset_1();check_pre_1();wr_ds18_1(0xcc);wr_ds18_1(0xbe);a=rd_ds18_1();b=rd_ds18_1();i=b;/*若b为1则为负温*/i=(i>>4);if(i==0){f=0;TMP=((a>>4)|(b<<4));a=(a&0x0f);TMP_d=a;}else{f=1;a=~a;a=(a+1);b=~b;b=(b+1);m=a;a=a>>4;b=b<<4;TMP=(a|b);m=(m&0x0f);TMP_d=m;}EA=1;return(TMP_d);}voiddelay(unsignedintx){unsignedinti;for(i=0;i<x;i++);}voiddisplay(unsignedchard1,unsignedchard2,unsignedchard3,unsignedchard4){P2=a[d1];LED_0=0;delay(100);LED_0=1;P2=a[d2];LED_1=0;delay(100);LED_1=1;P2=a[d3];LED_2=0;delay(100);LED_2=1;P2=a[d4];LED_3=0;delay(100);LED_3=1;}
[我来评论]   回答者: yoyowind   2008-07-08 17:49   


[ 知识搜索 ]  [ ]  [ 告诉好友 ]  [ 打印本文 ]  [ 关闭窗口 ]

 
问题搜索
     
相关问题
等待您来回答
 
 
Powered by 0512IT
购物车(0)    站内信(0)     新对话(0)