主要用于停車場動態車位的檢測
支持三路超聲波一路ESP8266
ESP8266作為客戶端使用
單片機源程序如下:
- #include "stm32f10x.h"
- #include "stdio.h"
- #include "timer4_cap.h"
- #include "UltrasonicWave.h"
- #include "delay.h"
- #include "bsp_esp8266.h"
- #define CarRoom0 0
- #define CarRoom1 1
- #define CarRoom2 2
- void get_Diatance(u8 CarRoomx);
- void Car_Check(void);
- char j;
- u32 s[3];
- int main(void)
- {
- u8 flag_t;
- delay_init();
- /* USART1 配置模式為 115200 8-N-1,中斷接收 */
- ESP8266_Init();
-
- NVIC_Configuration();
-
- TIM4_Cap_Init(0xffff,72-1); //以1Mhz的頻率計數
- UltrasonicWave_Configuration();
- GPIO_ResetBits(GPIOC,GPIO_Pin_13);
- //printf("老子一切都OK是你下面的程序出問題了\r\n");
- delay_ms(1000);
- GPIO_SetBits(GPIOC,GPIO_Pin_13);
- while(!ESP8266_JoinAP("GXM110","123456789"));
- while(!ESP8266_Link_Server(enumTCP,"120.77.87.78","9876",Single_ID_0));//連接服務器
- while(1)
- {
- UltrasonicWave_StartMeasure();
- UltrasonicWave_StartMeasure2();
- UltrasonicWave_StartMeasure3();
- s[0] = tempup3;
- s[1] = tempup2;
- s[2] = tempup1;
- //printf("1:%d|2:%d|3:%d\r\n",s[2],s[1],s[0]);
- if(s[0]<=15||s[1]<=15||s[2]<=15)
- {
- Car_Check();
- flag_t = 0;
- }
- else if(s[0]>15&&s[1]>15&&s[2]>15)
- {
- if(!flag_t)
- {
- Car_Check();
- flag_t = 1;
- }
- }
- delay_ms(500);
-
- }
- }
- void Car_Check(void)
- {
- if(s[0]<15)
- {
- if(s[1]<15)
- if(s[2]<15)
- ESP8266_SendString(DISABLE,"1234 000",10,Single_ID_0);
- else
- ESP8266_SendString(DISABLE,"1234 001",10,Single_ID_0);
- else
- if(s[2]<15)
- ESP8266_SendString(DISABLE,"1234 010",10,Single_ID_0);
- else
- ESP8266_SendString(DISABLE,"1234 011",10,Single_ID_0);
-
- }
- else
- {
- if(s[1]<15)
- if(s[2]<15)
- ESP8266_SendString(DISABLE,"1234 100",10,Single_ID_0);
- else
- ESP8266_SendString(DISABLE,"1234 101",10,Single_ID_0);
- else
- if(s[2]<15)
- ESP8266_SendString(DISABLE,"1234 110",10,Single_ID_0);
- else
- {
- ESP8266_SendString(DISABLE,"1234 111",10,Single_ID_0);
-
- }
- }
- // macESP8266_Usart("AT+CIPCLOSE\r\n");
- // macESP8266_Usart("AT+ CWQAP\r\n");/* 斷開連接 */
- }
復制代碼
所有資料51hei提供下載:
Avatar_UltrasonicWave.rar
(328.49 KB, 下載次數: 143)
2017-12-9 00:09 上傳
點擊文件名下載附件
STM32多路超聲波及ESP8266 下載積分: 黑幣 -5
|