系統功能:
系統上電后OLED顯示智能門禁系統 Door:xxxxxx
初始化ESP8266完成后顯示 Door:Closed
短按按鍵SW4可打開電磁鎖OLED顯示Door:Open,約五秒后電磁鎖自動關閉OLED
顯示Door:Closed
根據“TCP調試助手使用說明”操作, 在調試助手界面發送Open后電磁鎖
打開OLED顯示Door:Open,約五秒后電磁鎖自動關閉電磁鎖顯示Door:Closed
主要功能模塊原理圖:
電源時鐘燒錄接口:
單片機和按鍵輸入電路:
系統控制電路:
資料獲取地址
系統主要功能模塊代碼
初始化代碼:
/* USER CODE BEGIN 1 *//* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init */InitVar();/* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_USART1_UART_Init();MX_USART2_UART_Init();/* USER CODE BEGIN 2 *///uart2打開接收中斷HAL_UART_Receive_IT(&huart2, (uint8_t*)&uart2RecBuff, 1);InitOled();InitOledDisp();//初始化ESP8266ESP8266_Init(); /* USER CODE END 2 */
系統控制代碼:
?
//系統信息更新void SystemControl(void){static uint8_t doorOpenCnt = 0;if(doorState==false){return;}//門鎖開時間 doorOpenCnt++;if(doorOpenCnt>=5){doorOpenCnt = 0;doorState = false;RELAY_OFF();}}
OLED顯示處理:
//處理OLED顯示內容void SystemDisplay(void){char textBuf[20];if(doorState==false){sprintf(textBuf,"Door:Closed");}else{sprintf(textBuf,"Door:Open ");}OledShowString(0, 3, (uint8_t*)textBuf, OLED_FONT_8X16);}
ESP8266命令處理:
?
//======================================================================// 函數名稱: ESP8266_GetCMD// 函數功能: 獲取并處理ESP8266返回的命令//=======================================================================void ESP8266_GetCMD(void){char textBuf[20];//如果接收完成if(ESP8266_WaitRecive()==REV_OK) {if(strstr((const char*)esp8266_buf, "0,CLOSED")){sysConnnect = false;}else if(strstr((const char*)esp8266_buf, "0,CONNECT")){sysConnnect = true;} else if(strstr((const char*)esp8266_buf, "+IPD,0,5:LedON")){LED_ON();sprintf(textBuf,"LedON OK"); ESP8266_SendData((unsigned char*)textBuf, strlen(textBuf));}else if(strstr((const char*)esp8266_buf, "+IPD,0,6:LedOFF")){LED_OFF(); sprintf(textBuf,"LedOFF OK"); ESP8266_SendData((unsigned char*)textBuf, strlen(textBuf));} else if(strstr((const char*)esp8266_buf, "+IPD,0,4:Open")){doorState = true;RELAY_ON();sprintf(textBuf,"relayOn"); ESP8266_SendData((unsigned char*)textBuf, strlen(textBuf));} ESP8266_Clear(); //清空緩存 }}
此設計提供的資料包含原理圖PCB(包含PDF,AD,立創EDA三個版本),源代碼,系統框圖,主程序流程圖,物料清單(包含使用到的器件手冊),功能操作說明等。