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

read tris register

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



Joined: 22 Sep 2003
Posts: 119

View user's profile Send private message

read tris register
PostPosted: Wed Apr 07, 2004 2:59 pm     Reply with quote

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 ,....


Question
asjad



Joined: 09 Mar 2004
Posts: 52
Location: Greater Manchester - UK

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 3:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 4:58 pm     Reply with quote

Something like this maybe,

Code:
#byte TRISC = 0x87
#bit C2 = TRISC.2

...

C2 = "your new value";


Exclamation
Haplo



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

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 5:43 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 08, 2004 6:28 am     Reply with quote

Thanks for your help, that's great.

Rgds,

Dan
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