#include
#define uchar unsigned char
#define uint unsigned
int sbit DQ=P1^3;//ds18b20与单片机连接口
sbit RS=P2^4;
sbit RW=P2^5;
sbit EN=P2^6;
unsigned char code str1[]={"temperature: "};
unsigned char code str2[]={" "};
uchar data disdata[5];
uint tvalue;//温度值
uchar tflag;//温度正负标志
/*************************lcd1602程序**************************/
void delay1ms(unsigned int ms)//延时1毫秒(不够精确的)
{
unsigned int i,j;
for(i=0;i0;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; i0; 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
}
关键词:
hll1987
进程
18B20
测温
+lcd1