View previous topic :: View next topic |
Author |
Message |
Prashant Patel
Joined: 19 Jul 2004 Posts: 33
|
Port PINs handling |
Posted: Tue Nov 30, 2004 2:38 pm |
|
|
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
|
|
Posted: Tue Nov 30, 2004 5:26 pm |
|
|
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
|
|
Posted: Tue Nov 30, 2004 6:41 pm |
|
|
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
|
|
Posted: Wed Dec 01, 2004 12:35 pm |
|
|
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
|
|
Posted: Wed Dec 01, 2004 1:23 pm |
|
|
Sorry about that, I didn't read close enough
In that case, you gave him the best answer |
|
|
|