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

Using #bit

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



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

Using #bit
PostPosted: Wed May 14, 2003 8:30 pm     Reply with quote

<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
PostPosted: Wed May 14, 2003 10:12 pm     Reply with quote

:= 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
PostPosted: Thu May 15, 2003 1:14 am     Reply with quote

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
PostPosted: Thu May 15, 2003 5:02 am     Reply with quote

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.

#if defined(__PCM__)
#include <16f876.h>
#elif defined(__PCH__)
#include <18f252.h>
#endif

#define SELECT_PIN PIN_B0

#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
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