求助啊!sprintf()怎么操作?
本帖最后由 13692143637 于 2014-12-31 21:54 编辑新人发贴子,单片机初学!大神们帮忙看看是哪里有问题,下面是我在IAR FOR AVR 5.51写的温控代码,t1,t2,t3是ADC采集的数据,为什么在液晶只显示0.1F℃,并没有我想要那样呢?我把sprintf(stn,"%0.1f",(float)t1/10);改为sprintf(stn,"%d",t1/10);就可以显示,但是就没有小数点,我想要显示一位小数点。这个求大神指点迷津,
void Form_SystemRun1( int t1,intt2,intt3)
{
char stn;
sprintf(stn,"%0.1f",(float)t1/10); //
LCD_display("激统运行",0,48,0,8,1,0);
LCD_display("水箱温度",2,0,0,8,1,0);
LCD_display(" ",2,16,1,8,2,0);
LCD_display(stn,2,16,1,8,2,0);
LCD_display("℃",2,0,2,0,1,0);
sprintf(stn,"%0.1f",(float)t2/10);//
LCD_display("室温温度",4,0,0,8,1,0);
LCD_display(" ",4,16,1,8,2,0);
LCD_display(stn,4,16,1,8,2,0);
LCD_display("℃",4,0,2,0,1,0);
sprintf(stn,"%0.1f",(float)t3/10);//
LCD_display("设定温差",6,0,0,8,1,0);
LCD_display(" ",6,16,1,8,2,0);
LCD_display(stn,6,16,1,8,2,0);
LCD_display("℃",6,0,2,0,1,0);
}
在编译器中设置print为large模式,否则是不支持浮点转换的。 steaven2000 发表于 2015-1-15 15:55
在编译器中设置print为large模式,否则是不支持浮点转换的。
谢谢你!终于搞定了,前辈就是不一样!!太厉害了!{:handshake:} {:handshake:}
页:
[1]