View previous topic :: View next topic |
Author |
Message |
Guest
|
Printf disable if not in debug mode? |
Posted: Wed Jan 21, 2009 10:49 am |
|
|
Hi
I have a lot of statements in my code. The output is to RS232, I use the hardware com in my PIC.
Is it possible to make something smarter than:
Code: | if (debug) {printf("...");} |
The debug bit is changed in the software therefore a solution with "define will not work.
Because it will take a lot of modification time to make it running.
Any hints? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 21, 2009 1:51 pm |
|
|
You could re-write your printf statements to re-direct the output to
your own output routine. In that routine, you could check your debug
flag, and if it's True, then call putc(). If not, then just return. The
character will be thrown away. (The whole string will be thrown away) |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Jan 21, 2009 3:46 pm |
|
|
Hi
As this?
Code: | void DebugPrint(char c){
if (debug) {putc(c);}
} |
(can't remember what the printf is, if printing to a function, anyway it dosen't matter for the ex.)
Code: | printf(DebugPrint,"Print Test:%u\r\n",i); |
But then the cpu(PIC) still must run the hole printf process but nothing is sent out to RS232. The only time I save here is the RS232 timing?
Do I over look something? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 21, 2009 4:04 pm |
|
|
I thought your goal was to simply have output or not to have output.
I didn't know about your timing requirements. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Jan 21, 2009 4:16 pm |
|
|
Hi
Thanks for your help:-) |
|
![](templates/subSilver/images/spacer.gif) |
|