|
|
View previous topic :: View next topic |
Author |
Message |
ferrarilib
Joined: 11 Jun 2005 Posts: 38
|
printf questions |
Posted: Tue Jul 25, 2006 3:18 am |
|
|
I have do my litle code and now i want export it in lcd display .
my problem is that output of this assigns a lot of memory pic
example i have ;
if(A==0)
printf(lcd_putc,"\fWater press \n%4.2fBar",Buff/40.92);
if (A==1)
printf(lcd_putc,"\fTemperature \n%4.2fC",Buff/40.92);
if (A==2)
printf ( lcd_putc, "\f %05.0f RPM ", freq*60 );
ecc ..
there is a mode for global it ? because do out of memory pic .
i was try with atoi ,itoa funtions but is worse :(
sorry for my not good english
thanks. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Jul 25, 2006 10:42 am |
|
|
If your program is going to have a lot of printf() statements you might want to put the printf() in it's own routine and then have it called from other parts of the program. That way only one printf() will be taking up memory space.
Ronald |
|
|
ferrarilib
Joined: 11 Jun 2005 Posts: 38
|
|
Posted: Tue Jul 25, 2006 10:51 am |
|
|
thanks ronald !
i am doing so .
and %f4.2 ecc in eeprom so i cange format output with eeprom address thanks |
|
|
ferrarilib
Joined: 11 Jun 2005 Posts: 38
|
|
Posted: Wed Jul 26, 2006 5:24 am |
|
|
now i have do one global functions but my problem now is cange format in sprintf()
example ;
char BUFFER[25];
char Format[]="\f %4.2";
char Format1[]="\f %s";
ecc..
sprintf(BUFFER,Format,Dati);
output only ;
\f %4.2
or
\f %s
not the data format :(
there is metode fot do this ? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jul 26, 2006 6:21 am |
|
|
You can always write your own printf/sprintf |
|
|
Ttelmah Guest
|
|
Posted: Wed Jul 26, 2006 6:54 am |
|
|
There are two seperate 'big problems'. The first is that printing code is bulky. A 'generic' printf, would need to have the output routines to deal with all possible input format strings loaded, and would therefore be very large. CCS avoids this, by only loading the routines corresponding to the requested output forms.
The second problem though, is that CCS, does not support variable length argument lists. This is a basically 'essential' feature, to write your own printf. I suspect this is actually the core 'reason' why the CCS printf, is implemented the way it is, since as it is currently done, the compiler can decide during compilation, how many arguments there are, and code the actual function in each case, as if it has a fixed length argument list.
Realistically, if there are only a few choices, then the easiest solution, is to just have a system variable defining how you want a value printed, and then a subroutine, with a switch statement, based on this variable, and accepting the address of the value you want printed, selecting the required printf format.
Best Wishes |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jul 26, 2006 7:06 am |
|
|
Ttelmah wrote: | There are two seperate 'big problems'. The first is that printing code is bulky. A 'generic' printf, would need to have the output routines to deal with all possible input format strings loaded, and would therefore be very large. CCS avoids this, by only loading the routines corresponding to the requested output forms.
The second problem though, is that CCS, does not support variable length argument lists. This is a basically 'essential' feature, to write your own printf. I suspect this is actually the core 'reason' why the CCS printf, is implemented the way it is, since as it is currently done, the compiler can decide during compilation, how many arguments there are, and code the actual function in each case, as if it has a fixed length argument list.
Realistically, if there are only a few choices, then the easiest solution, is to just have a system variable defining how you want a value printed, and then a subroutine, with a switch statement, based on this variable, and accepting the address of the value you want printed, selecting the required printf format.
Best Wishes |
You can work around the variable arguments. See my scanf() code in the library. For just a few printf's, CCS's code would be smaller. But if the problem is that you have many printf's taking up way too much code, at some point it is worthwhile to write your own. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|