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

Clear RD4-RD7 w/o affecting RD0-RD3

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







Clear RD4-RD7 w/o affecting RD0-RD3
PostPosted: Tue Jan 25, 2005 1:07 pm     Reply with quote

Suppose I initially had TRISD set up like:

port_d = 0xF0; // Preload RD0-RD3 with 0000
TRISD = 0xF0; // Set the tris register

As you can see, RD4-RD7 are inputs, while RD0-RD3 are outputs.
I now want to change RD4-RD7 into outputs (i'm doing Enhanced CCP, but that isn't relevant to my question).

How do i preserve the values in RD0-RD3?

I've thought of:

temp_d = port_d;
temp_d = temp_d | 0xF0; // next manipulate the bits in temp_d
port_d = temp_d;
set_tris_d(0x00);

or maybe i should write:

temp_d = port_d;
temp_d = temp_d | 0xF0;
lat_d = temp_d;
set_tris_d(0x00);

Which is correct? Preloading port_d? or preloading LATD?

Thanks,
Mike
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 25, 2005 3:44 pm     Reply with quote

Better to use the LAT register. Look in the datasheet for read modify write to get a better understanding of why.
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