mikroC
making it simple...
Library Example
This code demonstrates use of I²C Library functions. PIC MCU is connected
(SCL, SDA pins ) to 24c02 EEPROM. Program sends data to EEPROM (data is
written at address 2). Then, we read data via I2C from EEPROM and send its
value to PORTD, to check if the cycle was successful (see the figure below how to
interface 24c02 to PIC).
void main(){
PORTB = 0;
TRISB = 0;
I2C_Init(100000);
I2C_Start();
I2C_Wr(0xA2);
I2C_Wr(2);
I2C_Wr(0xF0);
I2C_Stop();
Delay_ms(100);
I2C_Start();
I2C_Wr(0xA2);
I2C_Wr(2);
I2C_Repeated_Start();
I2C_Wr(0xA3);
PORTB = I2C_Rd(0u);
I2C_Stop();
}
MikroElektronika: Development tools - Books - Compilers
mikroC - C Compiler for Microchip PIC microcontrollers
// Issue I2C start signal
// Send byte via I2C
// Send byte (address of EEPROM location)
// Send data (data to be written)
// Issue I2C start signal
// Send byte via I2C
// Send byte (data address)
// Issue I2C signal repeated start
// Send byte (device address + R)
// Read the data (NO acknowledge)
(command to 24cO2)
(device address + W)
page
191
Need help?
Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?