标题: labview和stm32单片机通讯 [打印本页]

作者: 凹凸曼123    时间: 2021-3-23 23:03
标题: labview和stm32单片机通讯
基于labview做的上位机,单片机将采集到的火焰传感器AD值、烟雾传感器的值、温度传感器的值上传到上位机上。并且当温度超过一定值时触发报警。单片机上蜂鸣器上响,同时labview上出现弹窗警告。

作者: 凹凸曼123    时间: 2021-3-24 07:49
先分享单片机程序: 火灾报警.7z (211.58 KB, 下载次数: 27)
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "lcd.h"
  6. #include "usart.h"         
  7. #include "ds18b20.h"
  8. #include "exti.h"
  9. #include "beep.h"
  10. #include "adc.h"



  11. int main(void)
  12. {         
  13.         u8 t=0;               
  14.   u16        adcx1 = 0;
  15.         u16        adcx2 = 0;
  16.         short temperature;               
  17.   unsigned char buf[9]= {0};
  18.         delay_init();                     //延时函数初始化         
  19.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
  20.         uart_init(115200);                 //串口初始化为 115200
  21.         LED_Init();                                  //初始化与LED连接的硬件接口
  22.    EXTIX_Init();
  23.          BEEP_Init();
  24.          Adc_Init();
  25.          while(DS18B20_Init())        //DS18B20初始化        
  26.         {
  27.         }        
  28.         

  29.         while(1)
  30.         {            
  31.                   
  32.                  if(t%10==0)                        //每100ms读取一次
  33.                 {                        
  34.                         buf[0]=0xFF;
  35.             buf[8]=0xEE;
  36.                         temperature=DS18B20_Get_Temp();        
  37.       adcx1=Get_Adc_Average(ADC_Channel_1,30);
  38.       adcx2=Get_Adc_Average(ADC_Channel_2,30);
  39.                         adcx2 = 4096 - adcx2;
  40.                         buf[2] = adcx1>>8;
  41.                         buf[3] = adcx1;
  42.       buf[4] = temperature>>8;
  43.                         buf[5] = temperature;
  44.                         buf[6] = adcx2>>8;
  45.                         buf[7] = adcx2;

  46. //      buf[6] = temperature>>8;
  47. //                        buf[7] = temperature;
  48. //                         printf("temperature:%d ℃\r\n",(temperature/10));
  49. //                        printf("Fire Value:%d \r\n",adcx2);
  50. //                        printf("Smoking Value:%d \r\n",adcx1);
  51.                         
  52.                         if(adcx2 > 2000 || adcx1>3000||bool_warn ||temperature>700)
  53.                         {
  54.                                 buf[1] = 1;
  55. //                                printf("STATE: Fire warning \r\n\r\n\r\n");
  56.                                 bool_warn =1;
  57.                                 BEEP=1;        
  58.                         }
  59.                         else
  60.                         {
  61. //                        printf("STATE: SAFE \r\n\r\n\r\n");
  62.                                 buf[1] = 0;
  63.                         }
  64.             for(t=0;t<9;t++)
  65.                         {
  66. //                                 USART1->DR = buf[t];
  67.                                 USART_SendData(USART1, (u8)buf[t]);//向串口1发送数据
  68.                                 while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
  69.                         }               
  70.                 }               
  71.                
  72. //          printf("\r\n您发送的消息为:\r\n\r\n");         

  73.                  delay_ms(50);
  74.                 t++;
  75.                 if(t==20)
  76.                 {
  77.                         t=0;
  78.                         LED0=!LED0;
  79.                 }
  80.         }
  81. }

复制代码



作者: 凹凸曼123    时间: 2021-3-24 18:19
上位机界面

mmexport1616581105567.png (244.81 KB, 下载次数: 103)

mmexport1616581105567.png

IMG_20210321_204120.jpg (1.42 MB, 下载次数: 81)

IMG_20210321_204120.jpg

作者: dfghh139966    时间: 2021-3-27 15:00
这个可以有  我最近在做32单片机与matlab的通讯
作者: 芦苇劫    时间: 2021-3-28 00:13
上位机的源程序可以分享下吗




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1