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

Communication with 2 PIC16f877a by using I2C

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



Joined: 23 Sep 2010
Posts: 4

View user's profile Send private message

Communication with 2 PIC16f877a by using I2C
PostPosted: Thu Sep 23, 2010 1:27 am     Reply with quote

Hi, I'm new in the I2C. I wanted to turn on a LED through 2 PIC16F877a by using I2C communication. For example, PIC(a) will send signal to PIC(b) and the PIC(b) will turn on the LED. Can anyone post some sample code on how to do with this? I'm using CCS C Compiler...thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Thu Sep 23, 2010 2:32 am     Reply with quote

Look at ex_slave.c. This shows how to build an I2C slave, allowing you to read/write a memory buffer from the master.
change the 'main' in this to:

Code:

void main ()
{
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_SSP);

   while (TRUE) {
       if (buffer[0]==0) {
           output_high(PIN_A0);
       }
       else {
           output_low(PIN_A0);
       }
       delay_ms(100); //Just so the code is not reading the buffer all the time
   }
}

Then connect the LED to pin 'A0' - remember the resistor.....

Then the 'master' will need to be a master to write to a 24LC01 EEPROM, (examples here), and if you 'write' 0 to the first byte of the EEPROM, the LED will go on/off (depending which way round you wire the LED), write one, and the LED will change.

Best Wishes
siawjf



Joined: 23 Sep 2010
Posts: 4

View user's profile Send private message

PostPosted: Fri Sep 24, 2010 10:14 pm     Reply with quote

Then, how about the master code there, what should I write inside the master code?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Sat Sep 25, 2010 1:57 am     Reply with quote

Do a bit of searching. Try looking in the 'drivers' directory with the compiler, for '2401.c' for a start, then search on the forum for 24LC01.
_YOU_ need to do some of the work for yourself.
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