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

bit_test

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



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

bit_test
PostPosted: Mon Sep 05, 2011 12:23 pm     Reply with quote

Can someone please help me to understand the bit_test function because I can't understand it? I want to create a push button control and after 5 seconds that the user keep the button pressed, an action will be executed. The description that I found on the CCS C manual is this:

Tests the specified bit (0-7,0-15 or 0-31) in the given variable. The least significant bit is 0. This function is much more efficient than, but otherwise similar to: ((var & (1<<bit)) != 0)

Thanks for your help. I am assuming that the other similar function like bit_clear(), bit_set() use the similar structure.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Sep 05, 2011 6:10 pm     Reply with quote

In any variable or register that can be defined with the #DEFINE statement - this lets you logically test each bit. If it is a '1' the bit_test() of that bit number is true , else it is false.

So if you were to do this for say the 16f887:
Code:

#DEFINE PORTB 0x06

bit_test(portb,0);  // would return a true or false
                    // for second arguments of 0-7 
// based on the true or false state of logic voltages on the pins of portb
 
// and that is all there is to it
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