CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Debug flag

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
javick82



Joined: 12 Jul 2007
Posts: 43

View user's profile Send private message

Debug flag
PostPosted: Thu Apr 21, 2011 8:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 21, 2011 11:09 am     Reply with quote

#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

View user's profile Send private message

PostPosted: Thu Apr 21, 2011 11:20 am     Reply with quote

So now I know how not to do it, might there be a better way to do it?
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Apr 21, 2011 11:24 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Apr 21, 2011 11:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 21, 2011 11:28 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Apr 21, 2011 11:45 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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