English
Language : 

MCP9808-E-MS Datasheet, PDF (44/52 Pages) Microchip Technology – 0.5°C Maximum Accuracy Digital Temperature Sensor
MCP9808
/********************************************************************
*
Function Name: i2c_start
*
Return Value:
void
*
Parameters:
void
*
Description:
Send I2C Start Command
********************************************************************/
void i2c_start(void) {
PIR1bits.SSPIF = 0; //clear flag
while (SSPSTATbits.BF ); // wait for idle condition
SSPCON2bits.SEN = 1;
// initiate START condition
while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag
}
/********************************************************************
*
Function Name: i2c_repStart
*
Return Value:
void
*
Parameters:
void
*
Description:
Resend I2C Start Command
*
********************************************************************/
void i2c_repStart(void) {
PIR1bits.SSPIF = 0; // clear flag
while ( SSPSTATbits.BF ) ; // wait for idle condition
SSPCON2bits.RSEN = 1;
// initiate Repeated START condition
while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag
}
/********************************************************************
*
Function Name: i2c_stop
*
Return Value:
void
*
Parameters:
void
*
Description:
Send I2C Stop command
*
********************************************************************/
void i2c_stop(void) {
PIR1bits.SSPIF = 0; // clear flag
while ( SSPSTATbits.BF ) ; // wait for idle condition
SSPCON2bits.PEN = 1;
// Initiate STOP condition
while (!PIR1bits.SSPIF) ; // wait for a flag to be set
PIR1bits.SSPIF = 0; // clear flag
}
DS25095A-page 46
© 2011 Microchip Technology Inc.