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

Using PORTC & I2C

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



Joined: 06 Jul 2004
Posts: 9

View user's profile Send private message ICQ Number

Using PORTC & I2C
PostPosted: Wed Aug 04, 2004 7:34 am     Reply with quote

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







PostPosted: Wed Aug 04, 2004 7:57 am     Reply with quote

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...
PostPosted: Wed Aug 04, 2004 7:58 am     Reply with quote

Quote:
e.g. You want to write '101x x101' into RC3...


Should not be 'RC3'. I meant to write PORTC
Guest








Re: correction...
PostPosted: Wed Aug 04, 2004 8:51 am     Reply with quote

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







PostPosted: Wed Aug 04, 2004 10:16 am     Reply with quote

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