Hi all,
I am trying to understand a software implementation of the I2C protocol. I have found example code from this website https://www.elprocus.com/i2c-bus-protocol-tutorial-interface-applications/
Programming : start condition
I don't understand this part of code and comments are not helping much more
I can understand we are setting the port bits SDA and SCL to either low or high
but I don't know following
When do we need to set and clear (SDA or SCL) and why delay needed ?
I am trying to understand a software implementation of the I2C protocol. I have found example code from this website https://www.elprocus.com/i2c-bus-protocol-tutorial-interface-applications/
Programming : start condition
Code:
sbit SDA = P1^7; // initialize the SDA and SCL pins of the microcontroller//
sbit SCL = P1^6;
void delay(unsigned int);
void main ()
{
SDA=1; //processing the data//
SCL=1; //clock is high//
delay();
SDA=0; //sent the data//
delay();
SCL=0; //clock signal is low//
}
Void delay(int p)
{
unsignedint a,b;
For(a=0;a<255;a++); //delay function//
For(b=0;b<p;b++);
}
Code:
{
SDA=1; //processing the data//
SCL=1; //clock is high//
delay();
SDA=0; //sent the data//
delay();
SCL=0; //clock signal is low//
}
but I don't know following
When do we need to set and clear (SDA or SCL) and why delay needed ?