I have a small project that is pulling in an ADC value and converting it to a char string value with 8 bits....
Code: Select all
unsigned int myadc;
char adctxt[];
float aveadc;
myadc = ADC_Read(0);
aveadc = ((myadc * .6162) - 62.691);
FloatToStr(aveadc,adctxt);
result = 51.58397
What i would like to do is get rid of anything beyond 2 decimal places and pad the number before the decimal to 3 places. something like this....
result = 051.58
I tried to do that by cycling through the array with the result in it and making decisions based on where the decimal landed. unfortunately, I have had no luck getting this to work as expected. Here's the code......
Code: Select all
if(adctxt[0]="."){
retstr[0] = "0";
retstr[1] = "0";
retstr[2] = "0";
retstr[3] = ".";
retstr[4] = adctxt[1];
retstr[5] = adctxt[2];
}
if(adctxt[1]="."){
retstr[0] = "0";
retstr[1] = "0";
retstr[2] = adctxt[0];
retstr[3] = ".";
retstr[4] = adctxt[1];
retstr[5] = adctxt[2];
}
if(adctxt[2]="."){
retstr[0] = "0";
retstr[1] = adctxt[0];
retstr[2] = adctxt[1];
retstr[3] = ".";
retstr[4] = adctxt[2];
retstr[5] = adctxt[3];
}
if(adctxt[3]="."){
retstr[0] = adctxt[0];
retstr[1] = adctxt[1];
retstr[2] = adctxt[2];
retstr[3] = ".";
retstr[4] = adctxt[3];
retstr[5] = adctxt[4];
}
when I run this, it seems to print out garbage via the UART1_Write_Text(retstr).
Any ideas on what I might be doing wrong here??