www.pudn.com > TMP112.zip > Tmp112.c, change:2016-07-27,size:1041b


#include "pbdata.h" 
#include "Tmp112.h" 
 
void Init_Tmp(void) 
{ 
	IIC_Init(); 
} 
 
void WriteWord_Tmp(uint8_t nAddr,uint16_t nData) 
{ 
	IIC_Start(); 
	IIC_Send_Byte(0x90); 
	IIC_Wait_Ack(); 
	IIC_Send_Byte(nAddr); 
	IIC_Wait_Ack(); 
	IIC_Send_Byte((uint8_t)(nData>>8)); 
	IIC_Wait_Ack(); 
	IIC_Send_Byte((uint8_t)nData); 
	IIC_Wait_Ack(); 
	IIC_Stop(); 
} 
 
uint16_t ReadWord_Tmp(uint8_t nAddr) 
{ 
	union u_d RevMsg; 
	IIC_Start(); 
	IIC_Send_Byte(0x90); 
	IIC_Wait_Ack(); 
	IIC_Send_Byte(nAddr); 
	IIC_Wait_Ack(); 
	IIC_Start(); 
	IIC_Send_Byte(0x91); 
	IIC_Wait_Ack(); 
	RevMsg.bt.h1 = IIC_Read_Byte(1); 
	RevMsg.bt.l1 = IIC_Read_Byte(1); 
	IIC_Stop(); 
	return RevMsg.i1; 
} 
//输出负温度时,最高位为1 
uint16_t DispTmp(uint16_t nData) 
{ 
	uint16_t nResult = 0; 
	if((nData&0x8000)== 0x8000)//负温度 
	{ 
		nData = ~nData; 
		nData += 1; 
		nResult = (uint16_t)((float)nData * Accuracy * 0.0625); 
		nResult |= 0x8000; 
	}else 
	{ 
		nData>>=4; 
		nResult = (uint16_t)((float)nData * Accuracy * 0.0625); 
	} 
	return nResult; 
}