|
串口通訊實驗例程- #include "stm32f10x.h"
- #include "led.h"
- #include "usart.h"
- #include "lcd_2.6ips.h"
- #include "capture.h"
- #include "stdio.h"
- #include "delay.h"
- #include "key.h"
- #include "adc.h"
- #include "bsp_dht11.h"
- #include "bsp_ds18b20.h"
- #include "usart4.h"
- #include "stdlib.h"
- #include "string.h"
- #include "simxx.h"
- #include "SimUi.h"
- int main(void)
- {
- u8 Hum[20]={0},Temp[20]={0},WATER_TEMP[10]={0};
- u8 MQ[20]={0},vcc[20]={20};
- u8 send_flag=0;
- DHT11_Data_TypeDef data;
- u8 led_flag=0;
- Delay_init();
- LED_Init(); // LED初始化
- LCD_Init(); // LCD初始化
- time7_init();
- time7_set_timeout(10);
- Usart_Config();// 串口初始化
- DHT11_Init();
- DS18B20_Init();
- USART2_Config();
- Adc_Init();
- SimUi_InIt();
- USART2_printf(USART2,"串口二測試\r\n");
- USART2_printf(USART2,"初始化中..............\r\n");
- LCD_Clear(); // 清屏
- while(1)
- {
-
- if(sigRun[0]>sigRun[1])
- {
- if(Simxx_Signal())
- {
- LCD_DisplayString( 0,200 ,(u8 *)" ");
- LCD_DisplayString( 0,200 ,(u8 *)"Signal: Strong");
-
- }
- else
- {
- LCD_DisplayString( 0,200 ,(u8 *)" ");
- LCD_DisplayString( 0,200 ,(u8 *)"Signal: Weak");
- }
- sigRun[0]=0;
- }
-
-
- if(MQ_9Run[0]>MQ_9Run[1])
- {
- sprintf((char *)MQ,"harmful=%d%%",(Get_Adc(1)*100/4096));//獲得某個通道值
- LCD_DisplayString( 0,120 ,MQ);
- sprintf((char *)vcc,"WorkVcc=%.2fV",Get_Adc(4)*(3.3/4096));//獲得某個通道值
- LCD_DisplayString( 0,80 ,vcc);
- MQ_9Run[0]=0;
- }
-
- if(Dht11_Run[0]>Dht11_Run[1])
- {
- DHT11_Read_TempAndHumidity (&data);
- sprintf((char *)Hum,"Hum=%d.%d%%",data.humi_int,data.humi_deci);
- sprintf((char *)Temp,"Temp=%d.%dC",data.temp_int,data.temp_deci);
- LCD_DisplayString( 0,0 ,Hum);
- LCD_DisplayString( 0,40 ,Temp);
- Dht11_Run[0]=0;
- }
- if(DS18B20_Run[0]>DS18B20_Run[1])
- {
- sprintf((char *)WATER_TEMP,"WaterTemp=%.2fC",DS18B20_GetTemp_SkipRom ());
- LCD_DisplayString( 0,160 ,WATER_TEMP);
- DS18B20_Run[0]=0;
- }
- if(LED_Run[0]>LED_Run[1])
- {
-
- led_flag^=1;
- LED1_ST(led_flag);
- LED_Run[0]=0;
- }
- if(Simxx_Read_Nes())
- {
- send_flag=0;
- if(send_flag==0)
- {
- USART2_printf(USART2,"發送數據\r\n");
- send_flag=1;
- send_data(data.humi_int,data.humi_deci,data.temp_int,\
- data.temp_deci,DS18B20_GetTemp_SkipRom(),(Get_Adc(1)*100/4096));
- }
- }
-
- if(IrRun[0]>IrRun[1])
- {
- USART2_printf(USART2,"進入休眠\r\n");
- GPIO_ResetBits(LCD_BL_PORT,LCD_BL_PIN);
- if(KEY_Scan())
- {
- USART2_printf(USART2,"退出\r\n");
- IrRun[0]=0;
- GPIO_SetBits(LCD_BL_PORT,LCD_BL_PIN); //開啟LCD背光
- }
- }
-
-
- Delay_ms(10);
- }
- }
復制代碼
|
|