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

Port PINs handling

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



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

Port PINs handling
PostPosted: Tue Nov 30, 2004 2:38 pm     Reply with quote

Hi..

We are using PIC18F4585 .
(1)
How can we set the direction of some of the Port PINs and
leave the other PINs as it is? As we are using some of the
port PINs for different functionalities.

e.g
for port C we have configured RC3/SCL and RC4/SDA PINs for
DAC using I2C. And we want to use other port PINs as OUTPUT.
Can we set rest of the PINs OUTPUT keeping these two PINs
unaffected?

(2)
If we want to send the output data to only some of the PINs
using only one instruction then can we do that?

i.e
OUTPUT_B(0xF0); // for output the data to all the PINs.
OUTPUT_HIGH(PIN_B2); // for output the data to only one PIN.


Thanx in advanced...

Regards
Prashant
valemike
Guest







PostPosted: Tue Nov 30, 2004 5:26 pm     Reply with quote

There is no instruction to be able to set on the same ports - some pins high, some pins low, some untouched.

But you can build up a bitmask register to do this.

e.g.
say you want to set rc2 to 1 and clear rc7 to 0, all at the same time

temp = port_c;
temp &= ~0x80; // clears bit7 1000 0000 --> 0111 1111
temp |= 0x04; // sets bit 2 0000 0100

// now temp contains the bits you want
port_c = temp; // this stores temp into portc

As for i2c, i THINK if you are using HW i2c, and have your PIC configured for hardware i2c (not software i2c), then rc3 and rc4 will be unaffected.
Mark



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

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

PostPosted: Tue Nov 30, 2004 6:41 pm     Reply with quote

Quote:
There is no instruction to be able to set on the same ports - some pins high, some pins low, some untouched.


Well that's not quite right. Ever hear of bit_set() & bit_clear? You can change a single bit in a register without affecting the rest of the register. The tris registers are the ones to control whether its an input or output. You can also write a byte to the register defining the inputs and outputs at the same time.
valemike
Guest







PostPosted: Wed Dec 01, 2004 12:35 pm     Reply with quote

Mark, I was assuming that he wanted to write data (some bits high/some bits low) out to a port all at the same time, w/o the microsecond glitches if he set and cleared bits individually one after the other. At least that's how i understood his question #2.
Mark



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

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

PostPosted: Wed Dec 01, 2004 1:23 pm     Reply with quote

Sorry about that, I didn't read close enough Very Happy
In that case, you gave him the best answer Wink
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