DQ1 = 1; // 给脉冲信号 if(DQ1) dat|=0x80; delay_18B20(4); }
return(dat); }
/*************ds18b201写一个字节****************/
void WriteOneChar1(uchar dat) {
unsigned char i=0; for (i=8; i>0; i--) { DQ1 = 0; DQ1 = dat&0x01; delay_18B20(5); DQ1 = 1; dat>>=1; } }
/**************读取ds18b201当前温度************/
void ReadTemp1(void) { unsigned char a=0; unsigned char b=0; unsigned char t=0; long tt; Init_DS18B201(); WriteOneChar1(0xCC); // 跳过读序号列号的操作 WriteOneChar1(0x44); // 启动温度转换 delay_18B20(100); // this message is wery important Init_DS18B201(); WriteOneChar1(0xCC); //跳过读序号列号的操作 WriteOneChar1(0xBE); //读取温度寄存器等(共可读9个寄存器)度 delay_18B20(100); a=ReadOneChar1(); //读取温度值低位
前两个就是温

