当前位置:首页 > 基于单片机的温度采集显示电路设计
Delay1ms(1);
Ds18b20WriteByte(0xcc); //跳过ROM操作命令 Ds18b20WriteByte(0x44); //温度转换命令
// Delay1ms(100); //等待转换成功,而如果你是一直刷着的话,就不用这个延时了 }
/*******************************************************************************
* 函 数 名 : Ds18b20ReadTempCom * 函数功能 : 发送读取温度命令 * 输 入 : com * 输 出 : 无
*******************************************************************************/
void Ds18b20ReadTempCom() {
Ds18b20Init(); Delay1ms(1);
Ds18b20WriteByte(0xcc); //跳过ROM操作命令 Ds18b20WriteByte(0xbe); //发送读取温度命令 }
/*******************************************************************************
* 函 数 名 : Ds18b20ReadTemp * 函数功能 : 读取温度 * 输 入 : com * 输 出 : 无
*******************************************************************************/
int Ds18b20ReadTemp() {
int temp = 0; uchar tmh, tml;
Ds18b20ChangTemp(); //先写入转换命令
Ds18b20ReadTempCom(); //然后等待转换完后发送读取温度命令 tml = Ds18b20ReadByte(); //读取温度值共16位,先读低字节 tmh = Ds18b20ReadByte(); //再读高字节 temp = tmh; temp <<= 8; temp |= tml; return temp;}
29
共分享92篇相关文档