8051 is not having the inbuilt I2C, so you need to have software i2c implementation
I2c code....
#define SDA P0_0
#define SCL P0_1
void I2CInit(){
SDA = 1;
SCL = 1;
}
void I2CStart(){
SCL = 1;
SDA = 0;
SCL = 0;
}
void I2CRestart(){
SCL = 0;
SDA = 1;
SCL = 1;
SDA = 0;
}
void I2CStop(){
SCL = 0;
SDA = 0;
SCL = 1;
SDA = 1;
}
void I2CAck(){ // Does the Ack signal need to be generated by code?
SDA = 0;
SCL = 1;
SCL = 0;
SDA = 1;
}
void I2CNak(){
SDA = 1;
SCL = 1;
SCL = 0;
}
void I2CSend(unsigned char Data){
unsigned char i;
for(i=0;i<8;i++){
SCL = 0;
if((Data&0x80)==0)
SDA = 0;
else
SDA = 1;
SCL = 1;
Data<<=1;
}
SCL = 0; // Why this clock and data lines to be assigned to these values at end? Is it must ?
SDA = 1; // Why this clock and data lines to be assigned to these values at end? Is it must ?
}
unsigned char I2CRead(){
unsigned char i, Data=0;
for(i=0;i<8;i++){
SCL = 0;
SCL = 1;
if(SDA)
Data |=1;
Data<<=1;
}
SCL = 0; // Why this clock and data lines to be assigned to these values at end? Is it must ?
SDA = 1;
return Data;
}