delay_18B20(5); DQ = 1; dat>>=1; } }
/**************读取ds18b20当前温度************/ void ReadTemp(void) { unsigned char a=0; unsigned char b=0; char t; long tt; Init_DS18B20(); WriteOneChar(0xCC); // 跳过读序号列号的操作 WriteOneChar(0x44); // 启动温度转换 delay_18B20(100); // this message is wery important Init_DS18B20(); WriteOneChar(0xCC); //跳过读序号列号的操作 WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) delay_18B20(100); a=ReadOneChar(); //读取温度值低位 b=ReadOneChar(); //读取温度值高位 temp_value=b<<4; temp_value+=(a&0xf0)>>4; t=a&0x0f; tt=t*625; xiaoshu=tt/1000; }
void temp_to_str() //温度数据转换成液晶字符显示 {
TempBuffer[0]=temp_value/10+'0'; //十位 TempBuffer[1]=temp_value%10+'0'; //个位 TempBuffer[2]='.';
TempBuffer[3]=xiaoshu+'0'; TempBuffer[4]=0xdf; TempBuffer[5]='C'; TempBuffer1[6]='\0'; }
void Delay1ms(unsigned int count) { unsigned int i,j; for(i=0;i<count;i++) for(j=0;j<120;j++);
前两个就是温度
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新初中教育AT89C51单片机的多点温度测量(14)全文阅读和word下载服务。
相关推荐: