#include <stdio.h>
#include <string.h>
#include "gpio.h"
#include "common.h"
#include "i2c.h"
#include "uart.h"
float L75_Temp;
void LM75A_Temp(void)
{
uint8_t Temp_Data[2]={0};
uint16_t Temp;
I2C_BurstRead(HW_I2C0, 0x48, 0x00, 0, Temp_Data, 2);
Temp=(uint16_t)Temp_Data[0];
Temp=(Temp<<8|Temp_Data[1])>>5;
if(!(Temp_Data[0]&0x80))
{
L75_Temp=Temp*0.125;
printf("当前温度:+%.3f度\r\n",L75_Temp);
}
else
{
L75_Temp=(0x800-Temp)*0.125;
printf("当前温度:-%.3f度\r\n",L75_Temp);
}
}
int main(void)
{
/* 开机延时 */
DelayInit();
/* UART 初始化 */
GPIO_QuickInit(HW_GPIOB, 6, kGPIO_Mode_OPP);
UART_QuickInit(UART0_RX_B2_TX_B1, 9600);
UART_ITConfig(HW_UART0, kUART_IT_Rx, true);
I2C_QuickInit(I2C0_SCL_PB03_SDA_PB04, 576000);
printf("LM75A温度传感器\r\n");
while(1)
{
LM75A_Temp();
GPIO_ToggleBit(HW_GPIOB, 6);
DelayMs(1000);
}
}
|