基于STM32C8T6的MLX90614-DCC非接触式红外无线测温系统
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "mlx90614.h"
#include "oled.h"
//温度的单位 ℃
unsigned char TempCompany[][16]=
{
0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,
0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00,/*"℃",0*/
};
int main(void)
{
uint8_t i,j,key,flag,flag_time;
float Temperature = 0; //温度数据变量(浮点型)
char TempValue[80] = {0}; //温度值(字符串)
delay_init(); //延时函数初始化
uart_init(115200);//串口初始化为115200
OLED_Init() ;
OLED_Clear() ;
KEY_Init();
LED_Init(); //LED端口初始化
SMBus_Init();
display();
for(i = 6;i < 7;i )
{
j = i - 6;
OLED_ShowCHinese16x16(i*16,2,j,TempCompany);
}
OLED_ShowString(40,2,"----",16);
while(1)
{
key=KEY_Scan(0);
if(key==KEY0_PRES)
{
flag=1;
flag_time=0;
GPIO_SetBits(GPIOA,GPIO_Pin_5); //PA.8 输出高
delay_ms(100);
GPIO_ResetBits(GPIOA,GPIO_Pin_5);
delay_ms(100);
GPIO_SetBits(GPIOA,GPIO_Pin_5); //PA.8 输出高
delay_ms(100);
GPIO_ResetBits(GPIOA,GPIO_Pin_5);
}
if(flag==1)
{
if(flag_time==0)
Temperature = SMBus_ReadTemp();
flag_time=1;
printf("Temperature = %f\r\n",Temperature); //在串口调试助手上打印结果
delay_ms(100);//不加延时的话在电脑串口助手上看不到效果
sprintf(TempValue,"%.1f", Temperature); //浮点型转换成字符串
//温度单位显示 (℃)
for(i = 6;i < 7;i )
{
j = i - 6;
OLED_ShowCHinese16x16(i*16,2,j,TempCompany);
}
OLED_ShowString(40,2,(uint8_t *)TempValue,16);//在在OLED上显示实际测量的温度
if(Temperature>36.5)
{
GPIO_SetBits(GPIOA,GPIO_Pin_5); //PA.8 输出高
GPIO_ResetBits(GPIOA,GPIO_Pin_6); //PD.2 输出高
}
else
{
GPIO_ResetBits(GPIOA,GPIO_Pin_5); //PA.8 输出高
GPIO_SetBits(GPIOA,GPIO_Pin_6); //PD.2 输出高
}
flag=0;
}
}
}
评论