- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there an inbuilt function that converts ADC's output values to decimal values(in C ) for display purpose.
Solved! Go to Solution.
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh yes, there are.
#include <stdio.h>
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
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh yes, there are.
#include <stdio.h>
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
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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); "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this
#include <stdio.h>
char Buffer[17]; // 16 chars for LCD-Line + /0 character
void main(void)
csprintf(Buffer,"%s = %d","Test",32767); // Buffer has now the string "Test = 32767"
LCD_PrString(Buffer);
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.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi bob,
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The format is a const string, so you have to use
csprintf(Buffer,"%s =%d","Test",32767)
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi bob,
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is the size of the buffer greater 12?
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Bopb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
manufacturer.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you know the size of your final string beforehand, it is better to declare the string buffer as
char Buffer[13] 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.
-Arvind