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

#define to a pin and testing to a variable

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



Joined: 24 Mar 2004
Posts: 21

View user's profile Send private message

#define to a pin and testing to a variable
PostPosted: Wed Mar 24, 2004 3:06 pm     Reply with quote

I have not been able to search out and answer in the list.
I have defines set to input pins. But when I try and test on those against int sized variables the results are not what I expect. Is my problem testing a bit against a byte even if the byte is a 1 or 0? Do I have to make a bit variable for testing? Am I being grossly ignorant?

#define Trig_source PIN_D0
int internal = 1;

if(Trig_source == internal)
run_internal();

When PIN_D0 is set high(simulated), the IF statement will never test true.
Thanks,
JIMc
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 24, 2004 3:51 pm     Reply with quote

Use the input() function to read the pin. Then test the value
returned by that function.
Jim McBride



Joined: 24 Mar 2004
Posts: 21

View user's profile Send private message

PostPosted: Wed Mar 24, 2004 4:22 pm     Reply with quote

OK will do. The #define seems to work fine for outputs. Not sure why I was expecting a variable to automatically grab an input from a port. wishful thinking...
Wanting to keep the code readable, the following works fine:

#define Trig_source PIN_D0
int internal = 1, external = 0;

if( input(Trig_source) == internal )
run_internal();

Thanks for the help!!
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