
// Returns 1 if error occured parameters pointer to buffer 
// for storing adc value and adc channel no.
bit read_pcf8591( uchar *adrdbuff, uchar adch)
{
	bit error;                // bit to store error.

	A24i2c_start();           // send start condition.
	error=A24i2c_out(0x90);   // send device address  + write.
	if (error)                // If nack received lit up a led.
		digdata[5]&=L_SCH;

    error=A24i2c_out(adch);       // send adc channel no.
	if (error)
		digdata[5]&=L_PROG;  // if nack recd lit up led.

	error=A24i2c_stop();      // send stop condition.
	if (error)                // If error occurs lit up a led
		digdata[5]&=L_REPEAT;

	A24i2c_start();           // send start condition.
	error=A24i2c_out(0x91);   // send device address + read
	if (error)                // If nack recd lit up led.
		digdata[5]&=L_SCH;

	*adrdbuff=A24i2c_in(0);   // Read value from adc send ack.
	*adrdbuff=A24i2c_in(1);   // Read value froma adc send nack.

	error=A24i2c_stop();      // send stop condition.
	if (error)                // if error occurs lit up led.
		digdata[5]&=L_REPEAT;

	return bit;               // return error to main prog.
}
