I cant get my head round this one. Iv been looking around on the net and it seems that the way that people usually do it in c, is to use the sprintf function, my compiler for the PIC does not support such libraries. i was wondering if any one know of how to do it.I managed to get code that converts int to a character string i tested it and it works fine. Id like to have something simialar to it. the code is bellow. Also could any tell me what the line marked with the arrow is doing, especially what it means by the "number%10". Thanks
void func1( int number ) {
int i;
char string[] = "0000000";
for( i = 6 ; number != 0 ; i-- )
string = number%10 + '0'; <---------------------
number = number/10;
}
Can't help you with C, but the simple answer is NOT to use floats, they are slow, take up loads of space, and are inaccurate - with sensible program design they are hardly ever required, use integers instead.
The approach is basically the same as with the integers. You use division and remainder operations to compute the mantissa. Then you use the integer routine to work on the exponent. On a 32 bit float on a 20MHz PIC you would be lucky to do the conversion in 25 to 50 milliseconds.
The book called the "Standard C Library" or "Numerical Recipes in C" might be good references.
Did you need to display decimal #'s on an LCD by chance.
I am trying to sense the period of a signal with the input capture on the PIC18 and then compute the frequency. The frequency is then going to be displayed on the LCD. I am going to have to store this frequency value as a float right? then convert it to a string to print it to my LCD module. Any ideas?