Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
Using #bit
Posted: Wed May 14, 2003 8:30 pm
<font face="Courier New" size=-1>Hi there
There are two ways of changing a pin's state. For example:
output_high(PIN_B0);
and:
#bit PORTB0=0x06.0
PORTB0=1;
The second method produces a much smaller code, but does it run a risk of the correct data memory bank not being selected?
__Ali</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514472
david smith Guest
Re: Using #bit
Posted: Wed May 14, 2003 10:12 pm
:= There are two ways of changing a pin's state. For example:
:=
:=output_high(PIN_B0);
:=and:
:=#bit PORTB0=0x06.0
:=PORTB0=1;
I always use the latter just for readability alone.
I know of no drawbacks. Provides clean syntax for 1-bit variables to ports.
For clarification to other readers, here's a usage snippet:
#BYTE PORTB = 6
...
#BIT spHighSW = PORTB.2
#BIT spMedSW = PORTB.1
#BIT spLowSW = PORTB.0
...
IF (spLowSW == 0) { ... do something
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514474
Tomi Guest
Re: Using #bit
Posted: Thu May 15, 2003 1:14 am
The difference:
the first form with STANDARD_IO (default) setting not only sets the pin to high but sets the port pin to output.
The second form just sets the bit in the port_x register. If that port pin is in input state (the associated bit is 1 in the tris_x register) then the port pin never changes.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514477
Woody Guest
Re: Using #bit
Posted: Thu May 15, 2003 5:02 am
The advantage of using the biult in functions is portability of code.
For instance the PIC18F252 can be pin compatible with PIC16F876 and provides a good migration path if the code won't fit. Writing in a style which allows compilation for either part greatly eases the pain of migration if the code won't fit.
Readability can be enhanced by using #defines to rename the actual pins and IO directives to control how the compiler deals with the TRIS registers.
#pragma USE STANDARD_IO(B)
/* Wth this directive, port bit and TRIS bit are changed */
output_low (SELECT_PIN );
#pragma USE FAST_IO(B);
/* Now only port pit is changed */
output_low (SELECT_PIN );
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514487
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