View previous topic :: View next topic |
Author |
Message |
Pilot
Joined: 06 Jul 2004 Posts: 9
|
Using PORTC & I2C |
Posted: Wed Aug 04, 2004 7:34 am |
|
|
I am new in PICC. I am using I2C Hardware in PORTC and i want to use other 6 pins for directly output (or input) numbers between 0 and 63, like
myout=52, without affecting the i2c pins/tris. what is the practical way of doing this? Thanks. |
|
|
valemike Guest
|
|
Posted: Wed Aug 04, 2004 7:57 am |
|
|
If you use hardware i2c, then the rc3(scl)/rc4(sda) pins are overrided by the MSSP module, so there is no need to worry what you write into the portc or latc bit positions.
Personally, what I would do if I was using software bitbanged i2c on the rc3/rc4 pins, then I would try to make rc0-rc2,rc5-rc7 as inputs. Otherwise i would just set each bit individually. If individual toggling is not an option, then I would do some bitmasks and logical or/and to leave those bits alone.
e.g. You want to write '101x x101' into RC3...
unsigned char temp_c;
temp_c = 0xA5; // 1010 0101
// Anding with 0x18 will give you 000X X000
// Or'ing with temp_c will give you 101X X101
// Thus you leave rc3 and rc4 alone
port_a = (port_a & 0x18) | temp_c;
Unless you are doing the above operations in an ISR, then you are guaranteed that you won't interfere in the middle of an i2c_read or i2c_write, since after all, there is only one thread of execution.
-Mike
p.s. just use the FORCE_HW option in the #use i2c( ) declaration and you don't have to worry. |
|
|
valemike Guest
|
correction... |
Posted: Wed Aug 04, 2004 7:58 am |
|
|
Quote: | e.g. You want to write '101x x101' into RC3... |
Should not be 'RC3'. I meant to write PORTC |
|
|
Guest
|
Re: correction... |
Posted: Wed Aug 04, 2004 8:51 am |
|
|
valemike wrote: | Quote: | e.g. You want to write '101x x101' into RC3... |
Should not be 'RC3'. I meant to write PORTC |
Thanks a lot for your reply
I wonder if it's possible using structures? |
|
|
valemike Guest
|
|
Posted: Wed Aug 04, 2004 10:16 am |
|
|
you mean bitfields in the structs?
Yes that's possible. I've seen examples of that.
I personally haven't used bitfield structs in the past since taking my C++ course in college. I've gotten used to and'ing and or'ing instead. |
|
|
|