单片机源程序如下:- //温度的单位 ℃
- 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,
- };
- float GY906_Temperature; //体温数据全局变量(浮点型)
- float GY906_Max_Temperature=37.5; //温度阈值
- int DS18B20_Temperature; //环境温度
- char GY906_TempValue[80] = {0}; //体温值(字符串)
- char DS18B20_TempValue[80] = {0}; //环境值(字符串)
- float Temperature_Compensation(float GY906_Temperature); //温度补偿函数
- void Display_Only_Temperature(void); //视觉数据为空,只判断温度
- int main(void)
- {
- char Visual;
-
- I2C_EE_Init();
- Beep_Init();
- delay_init();
-
- USART1_Config(); //语音模块串口初始化为9600
- USART2_Config(); //接收视觉数据串口初始化为115200
-
- OLED_Init() ;
- OLED_Clear() ;
- LED_GPIO_Config();
- SMBus_Init();
- DS18B20_Init();
- LED_RED_ON();
- //蜂鸣器关
- Beep_ON();
- while(1)
- {
- //第一行显示体温
- displayGY906();
- //第二行显示环境温度
- displayDS18B20();
- //显示温度正常
- displayTempOK();
- //显示距离正常
- displayDisOK();
- Display_Only_Temperature();
- if(GY906_Temperature>35)
- {
- if(GY906_Temperature<=GY906_Max_Temperature)
- {
- printf("体温正常");
- delay_ms(1200);
- }
- else if(GY906_Temperature>GY906_Max_Temperature)
- {
- displayTempERR();
- for(int i=0;i<2;i++)
- {
- BEEP();
- printf("体温异常,请注意");
- delay_ms(1200);
- delay_ms(1200);
- }
- }
- }
- //接收视觉数据
- // Visual=getchar();
- if(USART_GetFlagStatus(DEBUG_USART2, USART_FLAG_RXNE) == RESET)//RESET未接收
- {
- Display_Only_Temperature();
- displayTempOK();
- displayDisOK();
- //说明有人靠近
- if(GY906_Temperature>35)
- {
- if(GY906_Temperature<=GY906_Max_Temperature)
- {
- printf("体温正常");
- delay_ms(1200);
- }
- else if(GY906_Temperature>GY906_Max_Temperature)
- {
- displayTempERR();
- for(int i=0;i<2;i++)
- {
- //蜂鸣器响
- BEEP();
- printf("体温异常,请注意");
- delay_ms(1200);
- delay_ms(1200);
- }
- }
- }
- }
- if(USART_GetFlagStatus(DEBUG_USART2, USART_FLAG_RXNE) == SET)//SET接收
- {
- //温度正常,距离正常
- if((GY906_Temperature<=GY906_Max_Temperature)&&(Visual=='0'))
- {
- Display_Only_Temperature();
- //显示温度正常
- displayTempOK();
- //显示距离正常
- displayDisOK();
- //蜂鸣器关
- Beep_ON();
- }
- //温度正常,距离异常
- else if((GY906_Temperature<=GY906_Max_Temperature)&&(Visual=='1'))
- {
- Display_Only_Temperature();
- //显示温度正常
- displayTempOK();
- //显示距离报警
- displayDisERR();
- for(int i=0;i<2;i++)
- {
- //蜂鸣器响
- BEEP();
- printf("距离过近,请保持距离");
- delay_ms(1300);
- delay_ms(1200);
- }
- }
- //温度异常,距离异常
- else if((GY906_Temperature>GY906_Max_Temperature)&&(Visual=='1'))
- {
- Display_Only_Temperature();
- //显示温度报警
- displayTempERR();
- //显示距离报警
- displayDisERR();
- for(int i=0;i<2;i++)
- {
- //蜂鸣器响
- BEEP();
- printf("距离过近,请保持距离");
- delay_ms(1300);
- delay_ms(1200);
- }
- }
- //温度异常,距离正常
- else if((GY906_Temperature>GY906_Max_Temperature)&&(Visual=='0'))
- {
- Display_Only_Temperature();
- //显示温度报警
- displayTempERR();
- //显示距离正常
- displayDisOK();
- for(int i=0;i<2;i++)
- {
- //蜂鸣器响
- BEEP();
- printf("体温异常,请注意");
- delay_ms(1200);
- delay_ms(1200);
- }
- }
- }
- }
- }
- //温度补偿
- float Temperature_Compensation(float GY906_Temperature)
- {
- if(GY906_Temperature<35)
- return GY906_Temperature-=2;
-
- else if((GY906_Temperature>=35)&&(GY906_Temperature<36))
- return GY906_Temperature+=1;
-
- else if((GY906_Temperature>=36)&&(GY906_Temperature<=36.3))
- return GY906_Temperature+=0.5;
-
- else if((GY906_Temperature>=36.4)&&(GY906_Temperature<=36.6))
- return GY906_Temperature+=0.1;
-
- else if((GY906_Temperature>=37.0)&&(GY906_Temperature<=37.2))
- return GY906_Temperature-=0.3;
-
- else if(GY906_Temperature>=37.3)
- return GY906_Temperature;
- }
复制代码 原理图:无
仿真:无
Keil代码下载:
温度补偿-DS18B20-语言播报.7z
(194.09 KB, 下载次数: 22)
|