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 support@ccsinfo.com

bit_test () or input () ?

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







bit_test () or input () ?
PostPosted: Mon Jan 08, 2007 9:02 am     Reply with quote

Hello to all.

When I want to read if a button is pressed, is better to use:

#byte PORTB = 0x6
value = bit_test (portb,0)

or

value = input (PIN_B0)

???

Another question: using CCS bootloader, the only modify on my program is adding the line: #include <bootloader.h> , in all cases ?

Thank in advance, GIO
davekelly



Joined: 04 Oct 2006
Posts: 53
Location: Berkshire, England

View user's profile Send private message

PostPosted: Mon Jan 08, 2007 9:13 am     Reply with quote

For the bit test, I would go with the input (PIN_B0), which is portable if you change processors.
GIO
Guest







PostPosted: Tue Jan 09, 2007 5:24 am     Reply with quote

Thanks davekelly.

can I use value = input (pin) also for output pin , or in this case i sbetter to use value = bit_test (var, bit) ?

GIO
davekelly



Joined: 04 Oct 2006
Posts: 53
Location: Berkshire, England

View user's profile Send private message

PostPosted: Tue Jan 09, 2007 5:38 am     Reply with quote

GIO wrote:
can I use value = input (pin) also for output pin , or in this case i sbetter to use value = bit_test (var, bit) ?


For output pins, make sure you are using standard I/O (CCS compiler will change the tris depending on whether you want input or output automatically), then you can just use one of the output functions:

Code:

output_low (PIN_xx);
output_high (PIN_xx);
output_toggle (PIN_xx);

etc


It is best to use the input and output functions, as the CCS compiler has a builtin database of the registers to actually perform the I/O. If you change processors, particularly going from one family to another (eg 16F to 18F), the register numbers and methods are different. This way you just change the include for the processor, and the compiler does the rest.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Jan 09, 2007 8:12 am     Reply with quote

1)value = bit_test (var, bit);

2)value = input (pin);

3)value = input_state (pin);

Basically generate the same code. Depending of the use of the standard I/O #use preprocessor.

As a general rule I use:

1) To test a bit in a variable only.
2) To get the level in the selected pin. This change the tris accordingly.
3) To know if the selected pin, is an Inp or Out, it can read the I/O state of the
selected pin without changing the tris.

Quote:

can I use value = input (pin) also for output pin , or in this case i sbetter to use value = bit_test (var, bit) ?

Just to do it more readable I would use:
value = input_state (pin);



Humberto
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