在串口上能打印到小数点后一位,但是在tft屏幕上却只能输出整数,这是为什么
这是我的代码
ds18b20.c
float DS18B20_GetTemp_SkipRom ( void )
{
uint8_t tpmsb, tplsb;
short s_tem;
float f_tem;
DS18B20_SkipRom ();
DS18B20_WriteByte(0X44); /* 开始转换 */
DS18B20_SkipRom ();
DS18B20_WriteByte(0XBE); /* 读取温度 */
tplsb = DS18B20_ReadByte();
tpmsb = DS18B20_ReadByte();
s_tem = tpmsb<<8;
s_tem = s_tem | tplsb;
if( s_tem < 0 ) /* 负温度 */
f_tem = (~s_tem+1) * 0.0625;
else
f_tem = s_tem * 0.0625;
return f_tem;
}
main.c
while( 1 )
{
while( DS18B20_Init() )
printf("\r\n no ds18b20 exit \r\n");
printf("\r\n ds18b20 exit \r\n");
DS18B20_ReadId ( ucDs18b20Id1 ); // 读取 DS18B20 序号
printf ( "\r\传感器一的温度 %.1f\r\n", DS18B20_GetTemp_SkipRom ( ) );
Delay_ms(1000);
LCD_ShowString(60,90,240,16,16,"DS18B20_1 OK");
LCD_ShowString(60,170,200,16,16,"Temp0: C");
LCD_ShowNum(110,170,DS18B20_GetTemp_SkipRom ( ),2,16);
Delay_ms(1000);
|