ds18b20负温度显示问题
voidwendu_decimal(uintdat)//温度转换后送显示
{
floattemp;
if(temp=dat*0.625)
{
wendu_shi=temp/100;//取十位temp除不用定义类型
wendu_ge=((uint)temp)%100/10;//取个位temp求模要定义类型,为16位,故定义uint
wendu_shu=((uint)temp)%100%10;//取小数
wendu_fu=0;
}
else//负温度时
{
temp=(~temp+1)*0.0625*10;
wendu_shi=temp/100;//取十位temp除不用定义类型
wendu_ge=((uint)temp)%100/10;//取个位temp求模要定义类型,为16位,故定义uint
wendu_shu=((uint)temp)%100%10;//取小数
wendu_fu=-3;
}
lcd_write_com(0x80+0x40+10);//送显示
lcd_write_date(0x30+wendu_fu);
lcd_write_date(0x30+wendu_shi);
lcd_write_date(0x30+wendu_ge);
lcd_write_date(0x2e);
lcd_write_date(0x30+wendu_shu);
lcd_write_date(0xdf);//温度符号
lcd_write_date(0x43);
}
这样一段程序其实负温度我不会编写,请大家帮忙改一下让能正确显示负温度,好像就差了temp定义的一句话,
还有在正温度的时候,最前端显示的不是0,而是什么都不显示,到负温度的时候才显示-号