|
|
View previous topic :: View next topic |
Author |
Message |
GIO Guest
|
bit_test () or input () ? |
Posted: Mon Jan 08, 2007 9:02 am |
|
|
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
|
|
Posted: Mon Jan 08, 2007 9:13 am |
|
|
For the bit test, I would go with the input (PIN_B0), which is portable if you change processors. |
|
|
GIO Guest
|
|
Posted: Tue Jan 09, 2007 5:24 am |
|
|
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
|
|
Posted: Tue Jan 09, 2007 5:38 am |
|
|
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
|
|
Posted: Tue Jan 09, 2007 8:12 am |
|
|
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 |
|
|
|
|
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
|