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

Another newbie question

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



Joined: 07 May 2005
Posts: 28
Location: Campbell, CA

View user's profile Send private message

Another newbie question
PostPosted: Mon May 16, 2005 4:26 pm     Reply with quote

In the code below

Code:

IF (ToggleCounter1 ^ ToggleCounter2 ^ ToggleCounter3 ^ ToggleCounter4 ^ ToggleCounter5 ^ ToggleCounter6 ^ ToggleCounter7 ^ ToggleCounter8);
              {Output_bit(PIN_A0,0);

      ELSE                     
              Output_bit(PIN_A0,1)};
             


On the ELSE statement, I get an error message "A numeric expression must appear here".

What I'm tring to do is to test if any of the 8 ToggleCounters is TRUE, then set or reset Pin A0.
All of the ToggleCounters are INT1.

I can't figure out what is wrong. Can somebody help me?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon May 16, 2005 5:27 pm     Reply with quote

Syntax problem.

Remove the semi-colon after your expression then remove the curly braces before and after the else.... all you need are the two semicolons, one after each action statement.

Code:

IF (ToggleCounter1 ^ ToggleCounter2 ^ ToggleCounter3 ^ ToggleCounter4 ^ ToggleCounter5 ^ ToggleCounter6 ^ ToggleCounter7 ^ ToggleCounter8)
              Output_bit(PIN_A0,0);

      ELSE                     
              Output_bit(PIN_A0,1);

 

That should work... although I think you might want the logical OR rather than the bitwise OR...
iso 9001
Guest







PostPosted: Tue May 17, 2005 2:25 am     Reply with quote

Thats XOR there.

And you could use bitwise OR I think, it should be the same as evaluating out to a bool anyway.

Either way, you probably don't want XOR.
Charles Linquist



Joined: 07 May 2005
Posts: 28
Location: Campbell, CA

View user's profile Send private message

PostPosted: Tue May 17, 2005 6:40 am     Reply with quote

Thanks! The program compiles now, and I'll switch my operators - which brings up another question, when I have an int1 variable, and I want to AND or OR it, should I use the bitwise operator, or the regular operator, or does it matter?
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Tue May 17, 2005 9:42 am     Reply with quote

Whenever you want to see if something evaluates to "true" - i.e. in an if() or while() loop, you use the double and or double or: && or ||.

&& or || means "see if this is true" - & or | means "do a bitwise and/or". Probably not what you want in an if() or while() loop.
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