私はこの「単純な」コードを持っています。
union
{
unsigned int res;
char bytes[2];
} ADC;
char ADC_num[5];
float temprature;
void vis_temp (void) // Show temp..
{
signed int l, length;
unsigned int rem;
GO_nDONE=1; // initiate conversion on the channel 0
while (GO_nDONE) continue;
ADC.bytes[0]=ADRESL;
ADC.bytes[1]=ADRESH;
utoa(ADC_num, ADC.res, 10);
temprature = (float) ADC.res * 478.1 / 1024;
temprature = temprature - 50.0;
l = (signed int) temprature;
temprature -= (float) l;
rem = (unsigned int)(temprature* 1e1);
sprintf(&ADC_num, "%i.%u", l, rem);
温度が0度以下であることを読み取るADC_res
と(ピンの電圧、温度センサー)、プログラムは「-3.5」などではなく「0.65500」と書き込みます。私はその権利をsignedおよびunsignedintとして宣言すべきでした。それを修正するためのヒント、またはそれを変換する他の方法があります。