#include #include "i2c.h" /******************************************************************** * Function Name: WriteI2C * * Return Value: Status byte for WCOL detection. * * Parameters: Single data byte for I2C bus. * * Description: This routine writes a single byte to the * * I2C bus. * ********************************************************************/ unsigned char WriteI2C( unsigned char data_out ) { SSPBUF = data_out; // write single byte to SSPBUF if ( WCOL ) // test if write collision occurred return ( -1 ); // if WCOL bit is set return negative # else { while( BF ); // wait until write cycle is complete IdleI2C(); // ensure module is idle if ( ACKSTAT ) // test for ACK condition received return ( -2 ); else return ( 0 ); // if WCOL bit is not set return non-negative # } }