LM75AD温度传感器读写

#include "LM75AD.h"
#include "IIC.h"

//////////////////////////////////////////////////////////////////////////////////	 
/*
0x00  Temperature Register      
0x01  Configuration register  器件模式 写00普通模式(100ms更新一次温度值) 写01为ShutDown模式
0x02  Hysteresis register
0x03  Over_temperature shutdown register

Temp Register 
MSByte                LSByte
7   6  5  4  3  2  1  0  7  6  5  4 3 2 1 0
D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 X X X X X

D10=0    ℃=+(Temp Data×0.125) 	
D10=1    ℃=-(Temp Data×0.125)


Address Table
MSB          LSB
1 0 0 1 A2 A1 A0

1 0 0 1 0  0  1 0/1       =0x92
*/
/////////////////////////////////////////////////////////////////////////////////

 
//LM75AD IO初始化
void LM75AD_Init(void)
{
    I2C_WriteByte(0x01,0x00,LM75AD_ADDR);
}

float LM75_Temp(void)
{
    float tempture;
    int temp;
    temp=I2C_ReadByte(0x00,LM75AD_ADDR,2);
    tempture=temp>>5;
    return tempture*0.125;	
}
头文件
#ifndef __LM75AD_H
#define __LM75AD_H	 
#include "sys.h"
 
#define LM75AD_ADDR 0x92   //默认地址0x90 这里我将A0接至了VCC

void LM75AD_Init(void);
float LM75_Temp(void);
		 				    
#endif


猜你喜欢

转载自blog.csdn.net/return_oops/article/details/80965686
今日推荐