View previous topic :: View next topic |
Author |
Message |
siawjf
Joined: 23 Sep 2010 Posts: 4
|
Communication with 2 PIC16f877a by using I2C |
Posted: Thu Sep 23, 2010 1:27 am |
|
|
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
|
|
Posted: Thu Sep 23, 2010 2:32 am |
|
|
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
|
|
Posted: Fri Sep 24, 2010 10:14 pm |
|
|
Then, how about the master code there, what should I write inside the master code? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sat Sep 25, 2010 1:57 am |
|
|
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. |
|
|
|