Is there an inbuilt function that converts ADC's output values to decimal values(in C ) for display purpose.
Oh yes, there are.
and use the sprintf, csprintf functions. The latter is used when the format is a string constant (as usual).
Works correctly for floats with Designer 5.2
thank you Bob
tough I could not able to use it . I got one similar to it, " char *itoa (char *string, int value, int base); "
which convets integer values to string & can be easily displayed on an LCD using " LCD_PrString(CHAR * sRamString); "
char Buffer; // 16 chars for LCD-Line + /0 character
csprintf(Buffer,"%s = %d","Test",32767); // Buffer has now the string "Test = 32767"
You are totally free in specifying the format, have a look (http://publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html) at the specs. You can convert (and print) Floats, longs ints and chars.
i am faced with a similar problem, how to convert a floating point value to a string. my basic requirement is to send a float value to the hyperterminal display through UART. i am using PSoC designer 5.1 . when i use the sprintf function as shown below. the compiler shows out an error saying it expects pointer to flash char but found pointer to char.
sprintf(Buffer,"%s = %d","Test",32767);
The format is a const string, so you have to use
i tested my program with the function
csprintf(Buffer,"%s = %d","Test",32767);
actually the function is written inside an infinite while loop along with many other functions. what i observe is whenever this function is not active(commented out) the while loop works. but as soon as the function is made active and included the while loop terminates after a single run. i don't know what could have gone wrong.
Is the size of the buffer greater 12?
And for the floats have a look here http://www.cypress.com/?app=forum&id=1573&rID=43329 .
Probably you have to declare an integer and assign 32767 to it, maybe it is interpreted as a 32-bit number which will not be properly handled by sprintf.
Compilers handle printf()/sprintf() differently, eg. feature set, from one compiler
to another. Typically if printf() handles longs and floats, so does sprintf(). You can
look at .h, .inc files for the definitions typically to confirm, or consult compiler
If you know the size of your final string beforehand, it is better to declare the string buffer as
char Buffer rather than char * Buffer;
Here, the value is 13 assuming you have 12 characters ("Test = 32767") + 1 NULL terminator.
You can then use UART_PutString(Buffer) which sends the NULL terminated string out the TX.