基于51单片机的电子密码指纹锁无线WiFi通信原理图PCB

news/2024/11/25 4:54:20/

功能介绍:
0.本系统采用STC12C5A60S2-35I作为单片机,因本系统需要使用WiFi模块和指纹模块,两者均是串口串口通信,89C52只有一路串口,因此无法满足需求,STC12C5A60S2-35I加强型51具备两路串口。
1.采用LCD1602液晶显示相关信息
2.密码可通过矩阵键盘设置,解锁支持矩阵键盘和指纹
3.支持WiFi通信解锁功能
4.采用DC005作为电源接口可直接输入12V给整个系统供电,系统具备12V转5V电源模块

原理图:
在这里插入图片描述
在这里插入图片描述

PCB:
在这里插入图片描述

主程序:

#include "main.h"enum ModeFlag_Df modeFlag; //模式,正常开锁模式,设置密码模式,设置指纹模式
unsigned char stepCnt = 0;
char setIndex = 0;
xdata unsigned char dis0[16];
bit refreshFlag = 1;
unsigned char inpPasswd[4]; //输入密码
unsigned char Passwd[4] = {'0','0','0','0'}; //初始密码
unsigned char tempPasswd[4] = {'x','x','x','x'}; //临时密码
unsigned char tempEnable = 0; //临时密码使能
unsigned char isNewFlag = 1;void main()
{LOCK = OPEN; //锁打开DelayMs(200);LOCK = CLOSE; //锁关闭LCD_Init(); //初始化液晶LCD_DispStr(0, 0, "    Welcome!    "); //液晶开机显示界面DelayMs(200);DelayMs(200);DelayMs(200);LCD_DispStr(0, 0, "   Waiting...   "); //液晶开机显示界面Uart2_Init();Uart2_Send_Str("AT+CIPMUX=1\r\n", 13); //打开多连接DelayMs(50);Uart2_Send_Str("AT+CIPSERVER=1,8080\r\n", 21); //建立服务 端口号为8080DelayMs(200);IE2 &= 0xFE;            //串口2中断关闭DelayMs(200);Uart1_Init();  //初始化串口DelayMs(200);EEPROM_Init();DelayMs(200);//EEPROM_WriteByte(IS_NEW_ADDR, 1);ReadPassword(); //初次使用时屏蔽此句if (isNewFlag != 0){unsigned char i = 0;EEPROM_WriteByte(IS_NEW_ADDR, 0);for (i = 0; i < 4; i++){Passwd[i] = '0';}WritePassword();}LCD_Clear();LCD_DispStr(0, 0, "Fingerprint Lock"); //液晶开机显示界面
//    DelayMs(200);
//    DelayMs(200);DelayMs(200); //延时500MS,等待指纹模块复位Device_Check(); //校对指纹模块是否接入正确,液晶做出相应的提示
//    DelayMs(200);
//    DelayMs(200);DelayMs(200); //对接成功界面停留一定时间LCD_Clear();LCD_DispStr(0, 0, "Enter pw or fp: "); //显示Timer0_Init(); //初始化定时器while (1){if (refreshFlag == 1){refreshFlag = 0;if (modeFlag == NORMAL){if (stepCnt == 0){LCD_DispStr(0, 0, "Enter pw or fp: "); //显示LCD_DispStr(0, 1, "                ");}TR0 = 0;IE2 &= 0xFE;            //串口2中断关闭CTRL_BY_FPM10A_Find_Fingerprint(); //搜索指纹IE2 |= 0x01;            //串口2中断打开TR0 = 1;}else if (modeFlag == OLD_PW){if (stepCnt == 0){LCD_DispStr(0, 0, "Old Password:   "); //显示LCD_DispStr(0, 1, "                ");}}else if (modeFlag == SELECT_PW_FP){LCD_DispStr(0, 0, "A.Set Password  "); //显示LCD_DispStr(0, 1, "B.SetFingerprint");}else if (modeFlag == SET_PW){if (stepCnt == 0){LCD_DispStr(0, 0, "New Password:   "); //显示LCD_DispStr(0, 1, "                ");}}else if (modeFlag == SET_FP_SELECT){IE2 &= 0xFE;            //串口2中断关闭Into_FP();IE2 |= 0x01;            //串口2中断打开}else if (modeFlag == FIND_FP){IE2 &= 0xFE;            //串口2中断关闭FPM10A_Find_Fingerprint();IE2 |= 0x01;            //串口2中断打开}else if (modeFlag == ADD_FP){IE2 &= 0xFE;            //串口2中断关闭FPM10A_Add_Fingerprint();IE2 |= 0x01;            //串口2中断打开}else if (modeFlag == DELETE_FP){LCD_DispStr(0, 0, "   Empty All    ");LCD_DispStr(0, 1, "  A.Yes  B.No   ");}}IE2 &= 0xFE;            //串口2中断关闭Key_Process(Calkey_scan());IE2 |= 0x01;            //串口2中断打开}
}void Timer0_Init(void)
{AUXR &= 0x7F;		//定时器时钟12T模式TMOD &= 0xF0;		//设置定时器模式TL0 = 0x00;		//设置定时初值TH0 = 0x4C;		//设置定时初值 50msTF0 = 0;		//清除TF0标志TR0 = 1;		//定时器0开始计时ET0 = 1;        //开启定时器1中断PT0 = 1;EA = 1;  //总中断打开
}void Timer0_Routine(void) interrupt 1
{static unsigned int time_50ms = 0;TL0 = 0x00;		//设置定时初值TH0 = 0x4C;		//设置定时初值 50mstime_50ms++;if (time_50ms > 5) //定时显示{refreshFlag = 1;time_50ms = 0;//BUZZER = ~BUZZER;}}void Open_Lock(void) //打开电磁锁
{LOCK = OPEN;DelayMs(250);DelayMs(250);LOCK = CLOSE;
}void Into_FP(void)
{/**************进入主功能界面****************/if (setIndex == 0){LCD_DispStr(0, 0, " *Search finger "); //第一排显示搜索指纹LCD_DispStr(0, 1, "  Add     Delete"); //添加和删除指纹}else if (setIndex == 1){LCD_DispStr(0, 0, "  Search finger "); //第一排显示搜索指纹LCD_DispStr(0, 1, " *Add     Delete"); //添加和删除指纹}else if (setIndex == 2){LCD_DispStr(0, 0, "  Search finger "); //第一排显示搜索指纹LCD_DispStr(0, 1, "  Add    *Delete"); //添加和删除指纹}
}void ReadPassword(void)
{unsigned char i = 0;isNewFlag = EEPROM_ReadByte(IS_NEW_ADDR);for (i = 0; i < 4; i++){Passwd[i] = EEPROM_ReadByte(PASSWORD_ADDR + i);}
}void WritePassword(void)
{unsigned char i = 0;for (i = 0; i < 4; i++){EEPROM_WriteByte(PASSWORD_ADDR + i, Passwd[i]);}
}void Key_Process(unsigned char keyCode)
{static unsigned char count_num = 0;unsigned char i = 0;unsigned char j = 0;if (modeFlag == NORMAL){if (keyCode == 'A') //设置键{modeFlag = OLD_PW;}else if ((keyCode >= '0') && (keyCode <= '9')){stepCnt = 1;if (count_num <= 3){inpPasswd[count_num] = keyCode;// LCD_DispOneChar((count_num+6), 1, inpPasswd[count_num]);LCD_DispOneChar((count_num+6), 1, '*');count_num++;}if (count_num == 4){DelayMs(250);DelayMs(250);for (i = 0; i < 4; i++) //判断密码是否正确{if (inpPasswd[i] != Passwd[i])break;}if (tempEnable == 1) //可以输入临时密码{for (j = 0; j < 4; j++) //判断密码是否正确{if (inpPasswd[j] != tempPasswd[j])break;}}if (i == 4 || j == 4) //密码输入正确{if (j == 4){tempEnable = 0; //清空临时密码使能for (j = 0; j < 4; j++) //判断密码是否正确{tempPasswd[j] = 'x'; //清空临时密码//LCD_DispOneChar(0+j, 1, tempPasswd[j]); //显示状态}}LCD_DispStr(0, 1, "      Open      "); //显示状态Open_Lock();}else{LCD_DispStr(0, 1, "     Error      "); //显示状态Buzz_Times(2);}DelayMs(250);DelayMs(250);stepCnt = 0;count_num = 0;}}}else if (modeFlag == OLD_PW){if ((keyCode >= '0') && (keyCode <= '9')) //输入旧密码{stepCnt = 1;if (count_num <= 3){inpPasswd[count_num] = keyCode;// LCD_DispOneChar((count_num+6), 1, inpPasswd[count_num]);LCD_DispOneChar((count_num+6), 1, '*');count_num++;}if (count_num == 4){DelayMs(250);DelayMs(250);for (i = 0; i < 4; i++) //判断密码是否正确{if (inpPasswd[i] != Passwd[i])break;}if (i == 4) //密码输入正确{LCD_DispStr(0, 1, "     Right      "); //显示状态DelayMs(250);DelayMs(250);modeFlag = SELECT_PW_FP;}else{LCD_DispStr(0, 1, "     Error      "); //显示状态Buzz_Times(2);DelayMs(250);DelayMs(250);modeFlag = NORMAL; //返回最初界面}stepCnt = 0;count_num = 0;}}}else if (modeFlag == SELECT_PW_FP){if (keyCode == 'A'){modeFlag = SET_PW;}else if (keyCode == 'B'){modeFlag = SET_FP_SELECT;setIndex = 0;}}else if (modeFlag == SET_PW){if ((keyCode >= '0') && (keyCode <= '9')) //设置新密码{stepCnt = 1;if (count_num <= 3){Passwd[count_num] = keyCode;LCD_DispOneChar((count_num+6), 1, Passwd[count_num]);count_num++;}if (count_num == 4){DelayMs(250);DelayMs(250);LCD_DispStr(0, 1, "      OK        "); //显示状态WritePassword();DelayMs(250);DelayMs(250);modeFlag = NORMAL;stepCnt = 0;count_num = 0;}}else if (keyCode == 'B'){modeFlag = SELECT_PW_FP;}} else if (modeFlag == SET_FP_SELECT){if (keyCode == 'A') //确认{switch (setIndex){case 0: //搜索指纹modeFlag = FIND_FP;// FPM10A_Find_Fingerprint();break;case 1: //添加指纹modeFlag = ADD_FP;// FPM10A_Add_Fingerprint();break;case 2: //清空指纹modeFlag = DELETE_FP;// FINGERPRINT_Cmd_Delete_All_Model();break;}}else if (keyCode == 'B'){modeFlag = SELECT_PW_FP;}else if (keyCode == '*') //设置位置移动{setIndex--;if (setIndex < 0){setIndex = 2;}}else if (keyCode == '#') //设置位置移动{setIndex++;if (setIndex > 2){setIndex = 0;}}}else if (modeFlag == FIND_FP){if (keyCode == 'B'){modeFlag = SET_FP_SELECT;}}else if (modeFlag == DELETE_FP){if (keyCode == 'A'){LCD_DispStr(0, 0, "   Emptying     ");LCD_DispStr(0, 1, "                ");DelayMs(250);FINGERPRINT_Cmd_Delete_All_Model();FPM10A_Receive_Data(12);LCD_DispStr(0, 0, "   All empty    ");LCD_DispStr(0, 1, "                ");Buzz_Times(3);DelayMs(250);modeFlag = NORMAL;}else if (keyCode == 'B'){modeFlag = SET_FP_SELECT;}}if (keyCode == 'D'){modeFlag = NORMAL;stepCnt = 0;count_num = 0;setIndex = 0;}
}

实物演示视频:
https://www.bilibili.com/video/BV19r4y147zJ/


http://www.ppmy.cn/news/436941.html

相关文章

数字电路课程设计 密码锁

设计要求 1、设计一个密码锁的控制电路&#xff0c;当输入正确代码时&#xff0c;输出开锁信号以推动执行机构工作&#xff0c;用红灯亮、绿灯熄灭表示关锁&#xff0c;用绿灯亮、红灯熄灭表示开锁&#xff1b; 2、在锁的控制电路中储存一个可以修改的4位代码&#xff0c;当开…

手势密码锁

一、 手势解锁应用 分析 1.监听手指在view上的移动&#xff0c;首先肯定需要自定义一个view&#xff0c;重写touch began,touch move等方法&#xff0c;当手指移动到圈上时&#xff0c;让其变亮。可以通过button按钮来实现。 2.界面搭建 背景图片&#xff08;给控制器的view添…

VHDL电子密码锁设计

主要内容: 采用先进的EDA技术,利用MAX+PLUSⅡ工作平台和VHDL语言,设计一种新型的电子密码锁。该密码锁具有密码预置和误码报警等功能,用一片FPGA芯片实现。 摘要 本文介绍一种利用EDA技术和VHDL语言,在MAX+PLUSⅡ环境下,设计了一种新型的电子密码锁。它体积小、功耗低、…

android 手势密码锁 GestureLock

前言&#xff1a; android 开发技术多如繁星&#xff0c;完全掌握非一日之功&#xff0c;开发涉及的深度难以想象&#xff0c;越走越难&#xff0c;金字塔顶尖上的人越来越少&#xff0c;今天得demo主要涉及的是自定义组件&#xff0c;很多时候&#xff0c;我们在网上找了太多…

六位数字密码锁设计(数字电路,proteus仿真)

六位数字密码锁设计 设计要求 自行设置密码&#xff0c;长度6位密码正确&#xff0c;开锁&#xff0c;指示灯亮。按键需要有按键的“滴滴”声。密码输入错误3次&#xff0c;报警。所有按键必须采用触发输入形式。关注公众号”嵌入式小学生“&#xff0c;回复”密码锁“&#…

移动智能终端PIN码破解

1) Android程序调试桥&#xff08;Android debug bridge , adb&#xff09; adb是一个 客户端-服务器端 程序, 其中客户端是用来操作的电脑, 服务器端是android设备。 adb 的使用涉及以下3个主要部件&#xff1a; 在Android终端设备上运行的adbd&#xff1b; 在…

51单片机实现矩阵键盘密码锁

目录 实验目的实验现象硬件程序扫描函数主函数代码main.cmatrixKeyboard.hmatrixKeyboard.cDelay.hDelay.c 其他 实验目的 使用51单片机的矩阵键盘模块以及led1602显示屏&#xff0c;实现模拟密码锁。 实验现象 当程序烧录到单片机中后&#xff0c;led1602屏幕会显示文字。 …

Python密码锁屏窗体界面

程序示例精选 Python密码锁屏窗体界面 如需安装运行环境或远程调试&#xff0c;见文章底部微信名片&#xff0c;由专业技术人员远程协助&#xff01; 前言 这篇博客针对《Python密码锁屏窗体界面》编写代码&#xff0c; 原理上没有采用Windows自带锁屏模块&#xff0c;是通过软…