View previous topic :: View next topic |
Author |
Message |
javick82
Joined: 12 Jul 2007 Posts: 43
|
Debug flag |
Posted: Thu Apr 21, 2011 8:59 am |
|
|
I have a program that is using preprocessor "#if DEBUG" statements to output some data via RS232 if a debug flag (via "#define DEBUG") is set or cleared.
Ideally, what I would like to do is set the debug flag based on a pin-state (high or low), that will be controlled via jumpers when I get my new board. Of course I can do this by just reading the pin on startup and normal if/then statements, but is there a way to read the pin using a preprocessor method and set the DEBUG flag accordingly? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 21, 2011 11:09 am |
|
|
#if DEBUG works at compile-time, and if() statements work at run-time.
You want a jumper on the board to change the compile-time behavior.
How would that work ? The compiler running on the PC, has no
knowlege of any jumper settings on a board sitting on your desk, unless
you tell it with a #define statement. |
|
|
javick82
Joined: 12 Jul 2007 Posts: 43
|
|
Posted: Thu Apr 21, 2011 11:20 am |
|
|
So now I know how not to do it, might there be a better way to do it? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Thu Apr 21, 2011 11:24 am |
|
|
If ONLY debug info is going to that RS232 port, then simply have the PC(or whatever) device is receiving the data, set a port pin on the PIC.Several RS232 pins are available for that use. |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Thu Apr 21, 2011 11:26 am |
|
|
javick82 wrote: | So now I know how not to do it, might there be a better way to do it? |
Yeah, what you originally said in your first post:
Quote: |
Ideally, what I would like to do is set the debug flag based on a pin-state (high or low), that will be controlled via jumpers when I get my new board. Of course I can do this by just reading the pin on startup and normal if/then statements,
|
That's a perfectly fine way to control debugging code. |
|
|
javick82
Joined: 12 Jul 2007 Posts: 43
|
|
Posted: Thu Apr 21, 2011 11:28 am |
|
|
It's really going to be more of a maintenance/serious debugging issue. Generally, I am controlling a device via RS232, but the concept is that if a debugging issue arises, we could swap the jumper, connect to a PC and read a string of messages indicating what the controller is doing and what data it is receiving. |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Thu Apr 21, 2011 11:45 am |
|
|
A global variable will work fine for that. You can even change it while the system is running to debug on the fly if you want.
I'd also like to suggest that you invest in a cheap logic analyzer such as:
http://www.saleae.com/logic/
It's cheap ($150 for an 8 port analyzer) and the developer seems like a nice guy. I've got one and I really like it. You can use something like that to debug while the system is live and spy on the RS232 comm while it's happening. |
|
|
|