Pitx-sp software guide – Kontron pITX-SP User Manual
Page 28
KTD-S0003-C
Page 24
CPLD Interface
p
ITX-SP Software Guide
//*********************************************************
//* Clock out one bit
//*********************************************************
void I2C_Bit_Out (int bit_out)
{
if
(bit_out)
SDA_High
();
else
SDA_Low
();
I2C_Delay
();
SCL_High
();
I2C_Delay
();
SCL_Low
();
I2C_Delay
();
}
//*********************************************************
//* Clock in one bit
//*********************************************************
int I2C_Bit_In (void)
{
int
bit_in;
SDA_High
();
SCL_High
();
I2C_Delay
();
bit_in = SDA_Read ();
I2C_Delay
();
SCL_Low
();
I2C_Delay
();
return
bit_in;
}
//*********************************************************
//* Send one byte on the bus. No start or stop conditions
//* are generated here but i2c_error will be set according
//* to the result. Returns 1 on success, 0 if we lose the
//* arbitration or if the slave doesn't acknowledge the
//* byte. Check i2c_error for the actual result on error
//*********************************************************
int I2C_Byte_Out (int byte_out)
{
int bit_count = 8, bit_in;
while
(bit_count)
{
if (byte_out & 0x80)
I2C_Bit_Out
(TRUE);
else
I2C_Bit_Out
(FALSE);
byte_out <<= 1;
bit_count--;
}