程序如下:
float const Var_TtoV_T[2][15]=
{
{0, 3.8748106364/1e2, 4.4194434347/1e5, 1.1844323105/1e7,
2.0032973554/1e8, 9.0138019559/1e10, 2.2651156593/1e11,
3.6071154205/1e13, 3.8493939883/1e15, 2.8213521925/1e17,
1.4251594779/1e19, 4.8768662286/1e22, 1.0795539270/1e24,
1.3945027062/1e27, 7.9795153927/1e31},
{0, 3.8748106364/1e2, 3.3292227880/1e5, 2.0618243404/1e7,
-2.1882256846/1e9,1.0996880928/1e11,-3.0815758772/1e14,
4.5479135290/1e17, -2.7512901673/1e20}
};
float T_TtoV(float T)热电偶温度转换成电压
{
unsigned char i = 0;
float value = 0;
if((T < -270) || (T > 400.0))
{
return ERROR;
}
else if(T < 0)
{
value = Var_TtoV_T[0][14];
for(i = 14; i > 0; i--)
value = T * value + Var_TtoV_T[0][i-1];
}
else
{
value = Var_TtoV_T[1][8];
for(i = 8; i > 0;i--)
value = T * value+ Var_TtoV_T[1][i-1];
}
return value;
}
显示函数
LCD_shuzi(42,4,temper/10000);
LCD_shuzi(58,4,(temper%10000)/1000);
LCD_shuzi(74,4,(temper%1000)/100);
LCD_shuzi(90,4,temper%100/10);
LCD_shuzi(106,4,temper%10);
我用的是ICC avr编译器,温度值为浮点型的 转换函数运算返回值也是浮点型的,但是显示函数是整型的,我用强制类型转换编译不过去,提示错误是非法的类型转换,,,请问有什么好办法可以实现数据类型的抓换,并且不丢失精度问题 |