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

how to control by bit!

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



Joined: 07 Mar 2009
Posts: 14

View user's profile Send private message

how to control by bit!
PostPosted: Wed Jan 06, 2010 7:27 pm     Reply with quote

Hi all, I need some help to understand about controlling output ports by
bit. The code is as follows (PIC16F877A):
Code:

#define sensor1 PIN_D0
#define sensor2 PIN_D1
#define motor1 PIN_B0
#define motor2 PIN_B1

void main(){

     while (1){
          if(input(sensor1)==1 && input(sensor2)==1){
                  output_b(0b00000011);
          }
         
          else if(input(sensor1)==0 && input(sensor2)==1){
          output_b(0b00000001);
          }

          else if(input(sensor1)==1 && input(sensor2)==0){
          output_b(0b00000010);
          }

          else {
          output_b(0b00000000);
          }
    }
}

The question is instead of using
Code:
output_b(0b00000011);

can I do this:
Code:
 output_b(0b000000|motor1|motor2);
mickey231bhq



Joined: 06 Apr 2005
Posts: 19
Location: Formosa

View user's profile Send private message

PostPosted: Wed Jan 06, 2010 7:35 pm     Reply with quote

you can use "output_high" and "output_low".
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Jan 06, 2010 8:21 pm     Reply with quote

Try this:
Code:

#define mot1mask 0b00000001
#define mot2mask 0b00000010
-
-
-

Then you can turn the motors on and off with this:
Code:

output_b(mot1mask|mot2mask);  //both motors on
output_b(~mot1mask&~mot2mask);  //both motors off
output_b(mot1mask&~mot2mask|mot3mask&~mot4mask);  //motors 1&3 on, 2&4 off

_________________
The search for better is endless. Instead simply find very good and get the job done.
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