Mikroc - I2C - Master and Slave
Mikroc - I2C - Master and Slave
* Project name:
Master
* Description:
Master control for PIC 2 PIC I2C Communication
* Configuration:
MCU:
PIC16F876A
SW:
mikroC v6.0
* NOTES:
*/
//-----------------------------------------------------------------------------const Slave_Addy = 0x69;
void send(unsigned short send_data){
I2C_Init(100000);
I2C_Start();
I2C_Wr(Slave_Addy);
I2C_Wr(send_data);
I2C_Stop();
}
unsigned short read(){
unsigned short read_data;
I2C_Init(100000);
I2C_Start();
I2C_Wr(Slave_Addy + 1);
read_data = I2C_Rd(0);
delay_ms(100);
I2C_Stop();
return read_data;
}
void main(){
// Main program code place here.
// Use sub-routine "send" to send data to slave.
// Use "read" to read data from slave.
}
/*
* Project name:
Slave
* Description:
Slave code for PIC 2 PIC I2C Communication
Write data from Master to PORTB
Send PORTC data to Master
* Configuration:
MCU:
PIC16F876A
SW:
mikroC v6.0
* NOTES:
*/
//-----------------------------------------------------------------------------const Addy = 0x69;
// set I2C device address
const Delay_Time = 250;
// port check delay
//-----------------------------------------------------------------------------//
Global Processing Variables
//-----------------------------------------------------------------------------unsigned short j;
// just dummy for buffer read
unsigned short rxbuffer;
//
//
//
//
//
// all done,
// Nothing in buffer so exit