问答

汇集网友智慧,解决技术难题

文若远

TA的家园币:12  

  • 为什么我的LCD1602不能显示DS18B20采集的温度

    我的代码:#include"ds18b20.h"#include"delay.h"voidDS18B20_Rst(void){DS18B20_IO_OUT();//SETPG11OUTPUTDS18B20_DQ_OUT=0;//À­µÍDQdelay_us(750);//À­µÍ750usDS18B20_DQ_OUT=1;//DQ=1delay_us(60);//15US}u8DS18B20_Check(void){u8retry=0;DS18B20_IO_IN();//SETPG11INPUTwhile(DS18B20_DQ_IN&&retry=200)return1;elseretry=0;while(!DS18B20_DQ_IN&&retry=240)return1;return0;}u8DS18B20_Read_Bit(void)//readonebit{u8data;DS18B20_IO_OUT();//SETPG11OUTPUTDS18B20_DQ_OUT=0;delay_us(2);DS18B20_DQ_OUT=1;DS18B20_IO_IN();//SETPG11INPUTdelay_us(12);if(DS18B20_DQ_IN)data=1;elsedata=0;delay_us(60);returndata;}u8DS18B20_Read_Byte(void)//readonebyte{u8i,j,dat;dat=0;for(i=1;i1;if(testb){DS18B20_DQ_OUT=0;//Write1delay_us(2);DS18B20_DQ_OUT=1;delay_us(60);}else{DS18B20_DQ_OUT=0;//Write0delay_us(60);DS18B20_DQ_OUT=1;delay_us(2);}}}voidDS18B20_Start(void)//ds1820startconvert{DS18B20_Rst();DS18B20_Check();DS18B20_Write_Byte(0xcc);//skipromDS18B20_Write_Byte(0x44);//convert}u8DS18B20_Init(void){DS18B20_Rst();returnDS18B20_Check();}shortReadTemperature(void){u8temp;u8TL,TH;shorttem;DS18B20_Start();//ds1820startconvertDS18B20_Rst();DS18B20_Check();DS18B20_Write_Byte(0xcc);DS18B20_Write_Byte(0xbe);TL=DS18B20_Read_Byte();//LSBTH=DS18B20_Read_Byte();if(TH>7){TH=~TH;TL=~TL;temp=0;}elsetemp=1;tem=TH;temi)&0x01)