UINT8 IIC_read_byte(UINT16 address){
UINT8 data;
IICC_TXAK = 0; // RX/TX = 1; MS/SL = 1; TXAK = 0
IICC |= 0x30; // And generate START condition
IICD = (0xA0); // Address the slave and set up for master transmits
while (!IICS_IICIF); // wait until IBIF
IICS_IICIF=1; // clear the interrupt event flag
while(IICS_RXAK); // check for RXAK
//-----Slave ACK occurred------------
IICD = ((UINT8)(address>>8)); // Send high byte of the word address
while (!IICS_IICIF); // wait until IBIF
IICS_IICIF=1; // clear the interrupt event flag
while(IICS_RXAK); // check for RXAK
//-----Slave ACK occurred------------
IICD = ((UINT8)address); // Send low byte of the word address;
while(IICS_RXAK); // check for RXAK;
while (!IICS_IICIF); // wait until IBIF;
IICS_IICIF=1; // clear the interrupt event flag;
//-----Slave ACK occurred------------
IICC_RSTA = 1; // set up repeated start
IICD = (0xA1); // (slave_address) | (RW = 1)
while (!IICS_IICIF); // wait until IBIF
IICS_IICIF=1; // clear the interrupt event flag
while (IICS_RXAK); // check for RXAK
//-----Slave ACK occurred------------
IICC_TX = 0; // set up to receive
IICC_TXAK = 1; // acknowledge disable
data = IICD; // dummy read
while (!IICS_IICIF); // wait until IBIF
IICS_IICIF=1; // clear the interrupt event flag
IICC_MST = 0; // generate stop signal
data = IICD; // read right data
return(data);
}