bool INL Write(unsigned char data_out)
{
unsigned char index;
// An I2C output byte is bits 7-0 (MSB to LSB). Shift one bit at a time to
// the SDATA output, and then clock the data to the I2C Slave device.
// Send 8 bits out the port
for(index = 0; index < 8; index++)
{
// Output the data bit to the device
SetSDATA(((data_out & 0x80) ? 1 : 0));
data_out <<= 1; // Shift the byte by one bit
SetSCLK(1); // Set SCLK high
SetSCLK(0); // Set SCLK low
}
SetSDATA(1); // Set SDATA input/high
SetSCLK(1); // Set SCLK high
if (!GetSDATA())
{
SetSCLK(0); // Set SCLK low
return true; // ACK from slave
} else
{
SetSCLK(0); // Set SCLK low
return false; // NACK from slave
}
} |