User`s manual
After configuring the I2C master mode, you have the following functions and pro-
cedures at your disposal:
sub function I2C_start as byte
Determines if I2C bus is free and issues START condition; if there is no error,
function returns 0.
sub procedure I2C_Repeated_Start
Performs repeated start condition.
sub function I2C_Write(dim Data as byte) as byte
After you have issued a start or repeated start you can send data byte via I2C bus;
this function also returns 0 if there is no errors.
sub function I2C_Read(dim Ack as byte) as byte
Receives 1 byte from the slave; and sends not acknowledge signal if parameter
Ack is 0 in all other cases it sends acknowledge.
sub procedure I2C_Stop as byte
Issues STOP condition.
The following code demonstrates use of I2C Library procedures and 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 EEP-
ROM and send its value to PORTD, to check if the cycle was successful. See the
following figure on how to interface 24c02 to PIC.
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
142
mikroBASIC
MikroElektronika: Development tools - Books - Compilers
Example
making it simple...
page