按键电子锁
-
思路讲解:通过矩阵键盘输入密码,与内置的密码进行对比,成功就是OK反之就是error。
-
先将延时模块,将LCD显示屏模块,矩阵键盘模块先引入。
-
#include <REGX52.H> #include "KEYbOARD.h" #include "LCD1602.h" unsigned char num; int pwd = 2345; int count; int password = 0; void main(){ LCD_Init(); LCD_ShowString(1,1,"password:"); while(1){ num = key(); //获取按键的值 if(num != 0){ if(num < 10){ //1-9,11是确定,12是取消 //密码区 if(count < 4){ password = password * 10; password = password + num%10; //数字左移 count++; } LCD_ShowNum(2,1,password,4); }else if(num == 11){ //确定 if(password == pwd){ LCD_ShowString(1,14,"ok"); password =