

unsigned char i2c_write(unsigned char ch)
{
	unsigned char twst;
	while ((SSCON & (1<<SI)) == 0) ;
	SSDAT = ch;
	SSCON = (1<<AA) | (1<<SSIE);
	while ((SSCON & (1<<SI)) == 0) ;
	switch (twst = TW_STATUS) {
		case TW_MT_SLA_ACK:
		case TW_MT_DATA_ACK:
		case TW_MR_SLA_ACK:
		case TW_MR_DATA_ACK: break;
		default: twst = 0; break;
	}
	return twst;
}

