View previous topic :: View next topic |
Author |
Message |
efox
Joined: 24 May 2006 Posts: 14
|
bitwise tris |
Posted: Sat Mar 07, 2009 4:06 pm |
|
|
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
|
|
Posted: Sat Mar 07, 2009 4:12 pm |
|
|
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
|
|
Posted: Sat Mar 07, 2009 4:37 pm |
|
|
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
|
|
Posted: Sat Mar 07, 2009 4:50 pm |
|
|
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
|
|
Posted: Sat Mar 07, 2009 5:29 pm |
|
|
thats probably a better response than with what i came up with.
thank you. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
actually this is what you asked for |
Posted: Sat Mar 07, 2009 6:52 pm |
|
|
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 |
|
|
|