|
在串口上能打印到小數(shù)點后一位,但是在tft屏幕上卻只能輸出整數(shù),這是為什么
這是我的代碼
ds18b20.c
float DS18B20_GetTemp_SkipRom ( void )
{
uint8_t tpmsb, tplsb;
short s_tem;
float f_tem;
DS18B20_SkipRom ();
DS18B20_WriteByte(0X44); /* 開始轉(zhuǎn)換 */
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);
|
|