系统功能:
系统上电后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三个版本),源代码,系统框图,主程序流程图,物料清单(包含使用到的器件手册),功能操作说明等。