This commit is contained in:
2026-03-20 21:19:53 +08:00
parent 9d3b4b836f
commit 6a749331db
125 changed files with 29972 additions and 23051 deletions

View File

@@ -1,18 +1,15 @@
#include "../main/SystemInclude.h"
//##############################################################################
#ifndef ENABLE_USE_MCP9808
#pragma message("[undefined] ENABLE_USE_MCP9808")
#elif(ENABLE_USE_MCP9808)
//##############################################################################
/* File start *****************************************************************/
#if 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 <20><>Address Byte<74><65>)
//also, make sure bit 0 is cleared <20><>0<EFBFBD><30>
SI2C_Write(MCP_ADR); // WRITE Command (see Section 4.1.4 <20><>Address Byte<74><65>)
// also, make sure bit 0 is cleared <20><>0<EFBFBD><30>
SI2C_Write(regBuf); // Write CONFIG Register
SI2C_Write(regData>>8); // Write data
SI2C_Write(regData); // Write data
@@ -24,15 +21,14 @@ u16 ReadWordRegister(u8 regBuf)
{
TypeWord tempInt;
//I2C_Init();
SI2C_Start(); // send START command
SI2C_Write(MCP_ADR); //WRITE Command (see Section 4.1.4 <20><>Address Byte<74><65>)
//also, make sure bit 0 is cleared <20><>0<EFBFBD><30>
SI2C_Write(MCP_ADR); // WRITE Command (see Section 4.1.4 <20><>Address Byte<74><65>)
// also, make sure bit 0 is cleared <20><>0<EFBFBD><30>
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 <20><>1<EFBFBD><31>
SI2C_Write(MCP_ADR | 0x01); // READ Command
// also, make sure bit 0 is set <20><>1<EFBFBD><31>
tempInt.Byte[1] = SI2C_Read(); // READ 8 bits
SI2C_Ack();
tempInt.Byte[0] = SI2C_Read(); // READ 8 bits
@@ -45,10 +41,9 @@ u16 ReadWordRegister(u8 regBuf)
/******************************************************************************/
void WriteByteRegister(u8 regBuf, u8 regData)
{
//I2C_Init();
SI2C_Start(); // send START command
SI2C_Write(MCP_ADR); //WRITE Command (see Section 4.1.4 <20><>Address Byte<74><65>)
//also, make sure bit 0 is cleared <20><>0<EFBFBD><30>
SI2C_Write(MCP_ADR); // WRITE Command (see Section 4.1.4 <20><>Address Byte<74><65>)
// also, make sure bit 0 is cleared <20><>0<EFBFBD><30>
SI2C_Write(regBuf); // Write CONFIG Register
SI2C_Write(regData); // Write data
SI2C_Stop(); // send STOP command
@@ -58,16 +53,15 @@ void WriteByteRegister(u8 regBuf, u8 regData)
u16 ReadByteRegister(u8 regBuf)
{
u8 temp;
//I2C_Init();
SI2C_Start(); // send START command
SI2C_Write(MCP_ADR); //WRITE Command (see Section 4.1.4 <20><>Address Byte<74><65>)
//also, make sure bit 0 is cleared <20><>0<EFBFBD><30>
SI2C_Write(MCP_ADR); // WRITE Command (see Section 4.1.4 <20><>Address Byte<74><65>)
// also, make sure bit 0 is cleared <20><>0<EFBFBD><30>
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 <20><>1<EFBFBD><31>
SI2C_Write(MCP_ADR | 0x01); // READ Command
// also, make sure bit 0 is set <20><>1<EFBFBD><31>
temp = SI2C_Read(); // READ 8 bits
SI2C_NoAck();
SI2C_Stop(); // send STOP command
@@ -75,6 +69,42 @@ u16 ReadByteRegister(u8 regBuf)
return temp;
}
//##############################################################################
#endif
//##############################################################################
/******************************************************************************/
void TestTemperatureInit(u8 regValue)
{
WriteWordRegister(CONFIG, CONVERSION);
//WriteByteRegister(RREG, RESULT_0_125_BIT);
WriteByteRegister(RREG, regValue);
HWState.EnableTempInit = 0;
}
/******************************************************************************/
s16 TestTemperature(void)
{
u32 tempLongInt;
s16 tempTA;
tempTA = (u32)ReadWordRegister(TA);
tempTA &= 0x1fff;
tempLongInt = (u32)(tempTA & 0xFFF);
if(tempTA >= 0x1000) tempLongInt = 0xFFF - tempLongInt;
tempLongInt = (tempLongInt * 6400) >> 10; // 0.0625*1024*100 /1024
if(tempTA >= 0x1000){
tempTA *= -1;
}
else tempTA = (u16)tempLongInt; // Temperature*100
if(voltageDetected[TPCB] >= 0x1000) tempTA *= -1;
return tempTA;
}
/******************************************************************************/
void TemperatureLowPower(void)
{
WriteWordRegister(CONFIG, SHUT_DOWN);
}
/* File end *****************************************************************/
#endif
/****************************************************************************/