float f1,f2,f3;
float Oldf1,Oldf2;
static unsigned char CRam1[32];
fltToa (float x, unsigned char *str,char precision)
{
/* converts a floating point number to an ascii string */
/* x is stored into str, which should be at least 30 chars long */
unsigned char *adpt;
int ie, i, k, ndig;
double y;
x=x+0.0000012; // <- le petit plus qui fait la difference de comportement!
ndig = ( precision<=0) ? 7 : (precision > 22 ? 23 : precision+1);
ie = 0;
/* if x negative, write minus and reverse */
if ( x < 0)
{
*str++ = '-';
x = -x;
}
else *str++ = ' '; // rajoute espace pour le signe +
/* put x in range 1 <= x < 10 */
if (x > 0.0) while (x < 1.0)
{
x *= 10.0; // a la place de =*
ie--;
}
while (x >= 10.0)
{
x = x/10.0;
ie++;
}
// in f format, number of digits is related to size
ndig += ie; // a la place de =+
//round. x is between 1 and 10 and ndig will be printed to
// right of decimal point so rounding is ...
for (y = i = 1; i < ndig; i++)
y = y/10.;
x += y/2.;
if (x >= 10.0) {x = 1.0; ie++;}
if (ie<0)
{
*str++ = '0'; *str++ = '.';
if (ndig < 0) ie = ie-ndig;
for (i = -1; i > ie; i--) *str++ = '0';
}
for (i=0; i < ndig; i++)
{
k = x;
*str++ = k + '0';
if (i == ie ) *str++ = '.';
x -= (y=k);
x *= 10.0;
}
*str = '\0';
}
// init Exponential filtering
EA2=Mesure_ADC(1);
f2=(float)EA2*0.40; // (4096 /1024 Points)
if (f2>60.0) f2=60.0;
if(f2<0.001) f2=0.0;
Oldf2=f2;
.... init nokia LCD ...
while(1)
{
//T° Int LM35DZ 0mV at 0°C
EA2=Mesure_ADC(1);
txt=Texte;
OUT_RS232
f2=(float)EA2* 0.4; // (4096 /1024 Points)
if (f2>60.0) f2=60.0;
if (f2<0.0) f2=0.0;
f3=0.2*f2+0.8*Oldf2; // K filter =0,2 et complement 1.0-0,20=0.80 K=1.0=NO filter K=0.0=) never refresh
Oldf2=f3;
k=sprintf(txt,"TInt=%s C",fltToa(f2,CRam1,2)); // 2 digits after the point
gotoxy(0,3);
Nokia_PutRamString(txt);
........
........
// or to keep allways the same number of digits, add spaces
fltToa(f3,CRam1,2);
k=strlen(CRam1);
if (k<6)
{
for (i=6;i>0;i--) CRam1[i]=CRam1[i-1];
CRam1[0]=' ';
}
k=sprintf(txt,"TInt= %s",CRam1); // xxx.xx
Nokia_PutRamString(txt);
// to find out where is the decimal point
//
fltToa(f3,CRam1,2);
k=strlen(CRam1)-2;
// decimal point is at k position !
// so at Cram1[k]
}