#include "../main/SystemInclude.h" //############################################################################## #ifndef ENABLE_USE_MCP9808 #pragma message("[undefined] ENABLE_USE_MCP9808") #elif(ENABLE_USE_MCP9808) //############################################################################## /******************************************************************************/ void WriteWordRegister(u8 regBuf, u16 regData) { //I2C_Init(); SI2C_Start(); // send START command SI2C_Write(MCP_ADR); //WRITE Command (see Section 4.1.4 ¡°Address Byte¡±) //also, make sure bit 0 is cleared ¡®0¡¯ SI2C_Write(regBuf); // Write CONFIG Register SI2C_Write(regData>>8); // Write data SI2C_Write(regData); // Write data SI2C_Stop(); // send STOP command } /******************************************************************************/ u16 ReadWordRegister(u8 regBuf) { TypeWord tempInt; //I2C_Init(); SI2C_Start(); // send START command SI2C_Write(MCP_ADR); //WRITE Command (see Section 4.1.4 ¡°Address Byte¡±) //also, make sure bit 0 is cleared ¡®0¡¯ SI2C_Write(regBuf); // Write CONFIG Register SI2C_Start(); // send Repeat START command SI2C_Write(MCP_ADR | 0x01); //READ Command //also, make sure bit 0 is set ¡®1¡¯ tempInt.Byte[1] = SI2C_Read(); // READ 8 bits SI2C_Ack(); tempInt.Byte[0] = SI2C_Read(); // READ 8 bits SI2C_NoAck(); SI2C_Stop(); // send STOP command return tempInt.Word; } /******************************************************************************/ void WriteByteRegister(u8 regBuf, u8 regData) { //I2C_Init(); SI2C_Start(); // send START command SI2C_Write(MCP_ADR); //WRITE Command (see Section 4.1.4 ¡°Address Byte¡±) //also, make sure bit 0 is cleared ¡®0¡¯ SI2C_Write(regBuf); // Write CONFIG Register SI2C_Write(regData); // Write data SI2C_Stop(); // send STOP command } /******************************************************************************/ u16 ReadByteRegister(u8 regBuf) { u8 temp; //I2C_Init(); SI2C_Start(); // send START command SI2C_Write(MCP_ADR); //WRITE Command (see Section 4.1.4 ¡°Address Byte¡±) //also, make sure bit 0 is cleared ¡®0¡¯ SI2C_Write(regBuf); // Write CONFIG Register SI2C_Start(); // send Repeat START command SI2C_Write(MCP_ADR | 0x01); //READ Command //also, make sure bit 0 is set ¡®1¡¯ temp = SI2C_Read(); // READ 8 bits SI2C_NoAck(); SI2C_Stop(); // send STOP command return temp; } //############################################################################## #endif //##############################################################################