; ::::::::::::: ; I2C Functions ; ::::::::::::: I2C_start: bset I2C1CON, #SEN ; start condition wait_start: btsc I2C1CON, #SEN ; start condition in progress? bra wait_start ; yes, wait return I2C_stop: bset I2C1CON, #PEN ; stop condition wait_stop: btsc I2C1CON, #PEN ; stop condition in progress? bra wait_stop ; yes, wait return I2C_restart: bset I2C1CON, #RSEN ; repeated start condition wait_rstart: btsc I2C1CON, #RSEN ; repeated start condition in progress? bra wait_rstart ; yes, wait return I2C_write: mov W11, I2C1TRN wait_write: btsc I2C1STAT, #TBF bra wait_write wait_slave_ack: btsc I2C1STAT, #TRSTAT bra wait_slave_ack return I2C_read: bset I2C1CON, #RCEN ; master receive enable wait_read: btsc I2C1CON, #RCEN bra wait_read mov I2C1RCV, W11 return I2C_ack: bset I2C1CON, #ACKEN ; send ack wait_ack: btsc I2C1CON, #ACKEN bra wait_ack return I2C_nack: bset I2C1CON, #ACKDT bset I2C1CON, #ACKEN ; send nack wait_nack: btsc I2C1CON, #ACKEN bra wait_nack bclr I2C1CON, #ACKDT return