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

bitwise tris

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



Joined: 24 May 2006
Posts: 14

View user's profile Send private message

bitwise tris
PostPosted: Sat Mar 07, 2009 4:06 pm     Reply with quote

So I didnt see a function to bitwise operation of the tris registers, and I tried googling, but didnt find exactly what i was looking for.

does anyone know of a simple way to change a tris bit without masking and so forth ?

I want to put this into a #define for a project that requires me to change tris values often enough to make me want to #define it.
efox



Joined: 24 May 2006
Posts: 14

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 4:12 pm     Reply with quote

does output_low() and output_high() force the pin to be an output ?

ie.

set_tris_b(0xff); //all input
output_b(0x0f)

does that mean that
B0-B3 are 5V whereas b4-b7 are 0v ?
efox



Joined: 24 May 2006
Posts: 14

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 4:37 pm     Reply with quote

nevermind...figured it out by looking at the c/asm output

for anyone that want to know,

output_high(pin) clears the tris bit and sets the port bit high
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 4:50 pm     Reply with quote

Making a set_tris() statement does nothing unless you have also declared a #use fast_io() for the same port. When using fast_io you are in direct control if a pin is an input or an output and must take care to ensure it's in a proper state while interfacing with the outside world.

There a very few times when I've needed to control the tris manually. One instance is while bit-banging an I2C bus. The compiler would change the state incorrectly which caused my slave devices to not respond. I usually just let the compiler handle if a port is an innie or an outtie

Setting a tris to be an input will simply make it float. If setting it to be an output the voltage level will be determined if the latch has been set to be high or low. Also, the input() command will make it an input, and it will remain an input until an output() command is executed.

There are always exceptions to every rule though. For instance, if you use the serial port the compiler will override any tris setting you have made when it uses the port.

Ronald
efox



Joined: 24 May 2006
Posts: 14

View user's profile Send private message

PostPosted: Sat Mar 07, 2009 5:29 pm     Reply with quote

thats probably a better response than with what i came up with.

thank you.
asmboy



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

View user's profile Send private message AIM Address

actually this is what you asked for
PostPosted: Sat Mar 07, 2009 6:52 pm     Reply with quote

i prefer the fixed, fast IO - where i set all the tris data - as i determine its requirement

d BTW: the function you were asking for - is already there !

see OUTPUT_drive()

and output_float()

where the argument is a single PIN like PIN_B3 ,
the first sets that PIN to tris OUTPUT mode
and the second sets input mode tris

just what you asked for
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