View previous topic :: View next topic |
Author |
Message |
dan king
Joined: 22 Sep 2003 Posts: 119
|
read tris register |
Posted: Wed Apr 07, 2004 2:59 pm |
|
|
Is there a way to read the tris register before setting it so a particular ports direction can be changed without affecting the other ports?
Say I want to change c.2 to output after it had been set to input without affecting any others, such as c.1, c.3, c.4 ,....
|
|
|
asjad
Joined: 09 Mar 2004 Posts: 52 Location: Greater Manchester - UK
|
|
Posted: Wed Apr 07, 2004 3:52 pm |
|
|
If you insert
#byte TRISC xxxxx
Where xxxxx is the address of TRISC in the actual PIC you are using
(look in PIC datasheet -SFR)
you can then read or write to it!
Hope this helps! _________________ Best Regards |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Wed Apr 07, 2004 4:58 pm |
|
|
Something like this maybe,
Code: | #byte TRISC = 0x87
#bit C2 = TRISC.2
...
C2 = "your new value"; |
|
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Wed Apr 07, 2004 5:43 pm |
|
|
I wouldn't recommend this method on PORTC though, because if you have any peripherals on PORTC, CCS will keep a shadow copy of TRISC and it might conflict with what you are doing. Always use set_tris_c() to write back to TRISC, don't do it directly. Look at this post for more info:
http://www.ccsinfo.com/forum/viewtopic.php?t=17970&highlight=
This code would be much better for changing the direction of RC2 to input:
Code: | #byte TRISC = 0x87
byte port_c_temp;
port_c_temp=TRISC;
bit_set(port_c_temp,2);
(or port_c_temp|=0b00000100; )
set_tris_c(port_c_temp);
|
|
|
|
dan king
Joined: 22 Sep 2003 Posts: 119
|
|
Posted: Thu Apr 08, 2004 6:28 am |
|
|
Thanks for your help, that's great.
Rgds,
Dan |
|
|
|