//----Write One Byte of Data----
void WriteI2CByte(uchar b) reentrant {
char i;
for (i = 0; i < 8; i++)
if ((b << i) & 0x80)
SEND_1();
else
SEND_0();
}
//----Read One Byte of Data----
uchar ReadI2CByte(void) reentrant {
char b = 0, i;
for (i = 0; i < 8; i++) {
SDA = 1;
DELAY(DELAY_TIME);
SCL = 1;
DELAY(DELAY_TIME);
F0 = SDA;
DELAY(DELAY_TIME);
SCL = 0;
if (F0 == 1) {
b = b << 1;
b = b | 0x01;
} else
b = b << 1;
}
return b;
}
//----write One Byte of Data,Data from MASTER to the SLAVER----
void Write_One_Byte(uchar addr, uchar thedata) { //Write "thedata" to the SLAVER's address of "addr"
bit acktemp = 1;
I2C_Start(); //IIC START
WriteI2CByte(0x6D << 1 + 0); //IIC WRITE operation, SLAVER address bit: 0x6D
acktemp = Check_Acknowledge(); //check the SLAVER
WriteI2CByte(addr); //address
acktemp = Check_Acknowledge();
WriteI2CByte(thedata); //thedata
acktemp = Check_Acknowledge();
I2C_Stop(); //IIC STOP
}
//----UART Send Byte----
void UART_SendByte(uchar dat) {
SBUF = dat; // Load data into SBUF
while (!TI); // Wait for transmission to complete
TI = 0; // Clear TI flag
}