/****************************************************************************/
//程序名称:     DS18b20头文件                
          
/****************************************************************************/
#ifndef __DS18B20_H__ 
#define __DS18B20_H__ 
//#include <reg52.h>
#include <intrins.h>    //包含_nop_()延时函数
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint  unsigned int
#endif
/******************************************************************************/
//温度传感器定义
sbit DQ = P3 ^ 7;//ds18B20
uint tvalue;//温度值
uchar tflag,flagdat;//温度正负标志
/******************************ds1820程序***************************************/
void delay_18B20(unsigned int i)//延时1微秒
{
  // while(i--);
  uint j; 
  for(;i>0;i--)
  for(j=12;j>0;j--);
} 
/******************************************************************************/
void ds1820rst()//ds1820复位*
{ unsigned char x=0;
DQ = 1;          //DQ复位
delay_18B20(4); //延时
DQ = 0;          //DQ拉低
delay_18B20(100); //精确延时大于480us
DQ = 1;          //拉高
delay_18B20(40); 
   } 
   unsigned char ds1820rd()//读数据
{ unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{   DQ = 0; //给脉冲信号
    dat>>=1;
    DQ = 1; //给脉冲信号
    if(DQ)
    dat|=0x80;
    delay_18B20(10);
}
   return(dat);
}
/******************************************************************************/
void ds1820wr(uchar wdata)//写数据
{unsigned char i=0;
    for (i=8; i>0; i--)
   { DQ = 0;
     DQ = wdata&0x01;
     delay_18B20(10);
     DQ = 1;
     wdata>>=1;
   }
}
read_temp()//读取温度值并转换
{uchar a,b;
ds1820rst();    
ds1820wr(0xcc);//跳过读序列号
ds1820wr(0x44);//启动温度转换
ds1820rst();    
ds1820wr(0xcc);//跳过读序列号
ds1820wr(0xbe);//读取温度
a=ds1820rd();
b=ds1820rd();
tvalue=b;
tvalue<<=8;
tvalue=tvalue|a;
    if(tvalue<0x0fff)
   tflag=0;
    else
   {tvalue=~tvalue+1;
tflag=1;
   }
tvalue=tvalue*(0.625);//温度值扩大10倍,精确到1位小数
return(tvalue);
}
/******************************************************************************/
#endif 
经测试用LCD12864显示正常