單片機源程序如下:- //溫度的單位 ℃
- 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)
2023-7-6 23:52 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|