/*
主功能部分
*/
#include "app_demo.h"
#include "time.h"
#include "lcd1602.h"
#include "beep.h"
#include "key.h"
#include "string.h"
#include "24c02.h"
#include "step_motor.h"
#include "public.h"
//控制管脚定义
sbit LED1=P2^2;
sbit LED2=P2^3;
sbit LED3=P2^4;
//继电器控制脚
sbit RELAY=P3^6;
//定义全局结构体变量
_sys_str sys_str;
//定时器0中断函数
void time0() interrupt 1
{
static u8 i=0;
TH0=0XDC; //给定时器赋初值,定时10ms
TL0=0X00;
i++;
if(i==100)//间隔1S读取温度
{
i=0;
}
}
//系统参数初始化
void sys_parm_init(void)
{
u8 userbuf[PSW_BITNUM]={9,9,0,4,2,8};//
u8 ownbuf[PSW_BITNUM]={6,6,6,6,6,6};//
u8 i=0;
sys_str.mode=0;
sys_str.pw_err=0;
sys_str.err_cnt=0;
sys_str.psw_flag=0;
sys_str.psw_resive=0;
sys_str.psw_ok=0;
sys_str.add_psw=0;
sys_str.id=0;
sys_str.add_err_cnt=0;
sys_str.del_psw=0;
sys_str.ret_psw=0;
// at24c02_write_one_byte(255,0x00);
if(at24c02_read_one_byte(255)!=0x18) //在AT24C02指定地址读出一个数据位置相同
{
at24c02_write_one_byte(255,0x18); //在AT24C02指定地址读出一个数据
//存储用户密码
for(i=0;i<PSW_BITNUM;i++)
{
at24c02_write_one_byte(i,userbuf[i]);
// lcd1602_show_num(i,0,userbuf[i],1);
}
//存储管理员密码
for(i=0;i<PSW_BITNUM;i++)
{
at24c02_write_one_byte(10+i,ownbuf[i]);
// lcd1602_show_num(i,0,ownbuf[i],1);
}
at24c02_write_one_byte(20,sys_str.id);
}
else
{
beep_alarm(100,20);
for(i=0;i<PSW_BITNUM;i++)
{
sys_str.save_psw[0][i]=at24c02_read_one_byte(i);
// lcd1602_show_num(i,1,sys_str.save_psw[0][i],1);
}
for(i=0;i<PSW_BITNUM;i++)
{
sys_str.save_psw[1][i]=at24c02_read_one_byte(i+10);
delay_ms(10);
// lcd1602_show_num(i,1,sys_str.save_psw[1][i],1);
}
sys_str.id=at24c02_read_one_byte(20);
}
// while(1);
}
//开机界面显示1
void open_show1(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Welcome Home");
lcd1602_show_string(0,1,"Hello!!!");
}
//按K4进入密码登陆页面
void open_show2(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Welcome Home");
lcd1602_show_string(0,1," Password: ");
}
//密码正确开锁成功显示
void psw_ok_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Password Success");
lcd1602_show_string(0,1,"Door Open!!!");
}
//手动关门显示
void door_close(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Door close");
lcd1602_show_string(0,1,"Later");
}
//密码错误开锁失败显示
void psw_error_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Password Error!!");
lcd1602_show_string(0,1,"Try again!!!");
}
//密码错3次界面显示
void psw_error1_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"10 S Try again");
lcd1602_show_string(0,1,"Time:");
}
//密码错4次界面显示
void psw_error2_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Password Error!!");
lcd1602_show_string(0,1,"Bell rings!!");
}
//输入管理员密码界面显示
void manager_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Manager Password");
lcd1602_show_string(0,1," Password:");
}
//管理员密码错误界面显示
void managererror_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Manager Password");
lcd1602_show_string(0,1,"Error!!!");
}
//输入旧密码界面显示
void reset_psw_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Init Password");
lcd1602_show_string(0,1," Password:");
}
//请输入最新密码显示
void new_psw_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"New Password");
lcd1602_show_string(0,1," Password:");
}
//请再次输入最新密码显示
void new_psw_once_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"New Psw again");
lcd1602_show_string(0,1," Password:");
}
//重置密码修改成功
void psw_modify_ok_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"New Password OK");
}
//输入初始密码错误界面显示
void init_psw_error_show(void)
{
lcd1602_clear();
lcd1602_show_string(0,0,"Init Password");
lcd1602_show_string(0,1,"Error!!!");
}
//按键选择开锁方式 K4
void key_choice_open_mode(void)
{
u8 key=0;
key=key_scan(0);
//开锁方式选择
if(key==KEY4_PRESS)
{
beep_alarm(100,20);//提示音
sys_str.mode=1;//键盘密码解锁方式
open_show2();
}
}
//修改密码
void reset_psw(void)
{
u8 key=0;
static u8 cnt=0;
static u8 tim=0;
static u8 new_psw[PSW_BITNUM];
u8 i=0;
reset_psw_show();//请输入初始密码
while(1)
{
key=key_matrix_flip_scan();
//初始密码记录
if(tim==0 || tim==1)
{
//数字1-3
if(key>=1&&key<=3)
{
beep_alarm(100,10);//提示音
if(cnt<PSW_BITNUM)//有效ID位数
{
sys_str.psw[cnt]=key;//记录用户输入密码
lcd1602_show_num(10+cnt,1,sys_str.psw[cnt],1);
cnt++;
}
}
//数字4-6
else if(key>=5&&key<=7)
{
beep_alarm(100,10);//提示音
if(cnt<PSW_BITNUM)//有效ID位数
{
sys_str.psw[cnt]=key-1;//记录用户输入密码
lcd1602_show_num(10+cnt,1,sys_str.psw[cnt],1);
cnt++;
}
}
//数字7-9
else if(key>=9&&key<=11)
{
beep_alarm(100,10);//提示音
if(cnt<PSW_BITNUM)//有效密码位数
{
sys_str.psw[cnt]=key-2;//记录用户输入密码
lcd1602_show_num(10+cnt,1,sys_str.psw[cnt],1);
cnt++;
}
}
//数字0
else if(key==14)
{
beep_alarm(100,10);//提示音
if(cnt<PSW_BITNUM)//有效密码位数
{
sys_str.psw[cnt]=key-14;//记录用户输入密码
lcd1602_show_num(10+cnt,1,sys_str.psw[cnt],1);
cnt++;
}
}
}
//新密码记录
else if(tim==2)
{
//数字1-3
if(key>=1&&key<=3)
{
beep_alarm(100,10);//提示音
if(cnt<PSW_BITNUM)//有效ID位数
{
new_psw[cnt]=key;//记录用户输入密码
lcd1602_show_num(10+cnt,1,new_psw[cnt],1);
cnt++;
}
}
//数字4-6
else if(key>=5&&key<=7)
{
beep_alarm(100,10);//提示音
if(cnt<PSW_BITNUM)//有效ID位数
{
new_psw[cnt]=key-1;//记录用户输入密码
lcd1602_show_num(10+cnt,1,new_psw[cnt],1);
cnt++;
}
}
//数字7-9
else if(key>=9&&key<=11)
{
beep_alarm(100,10);//提示音
if(cnt<PSW_BITNUM)//有效密码位数
{
new_psw[cnt]=key-2;//记录用户输入密码
lcd1602_show_num(10+cnt,1,new_psw[cnt],1);
cnt++;
}
}
//数字0
else if(key==14)
{
beep_alarm(100,10);//提示音
if(cnt<PSW_BITNUM)//有效密码位数
{
new_psw[cnt]=key-14;//记录用户输入密码
lcd1602_show_num(10+cnt,1,new_psw[cnt],1);
cnt++;
}
}
}
//清除输入
if(key==13)
{
beep_alarm(100,10);//提示音
cnt=0;
memset(sys_str.psw,0,PSW_BITNUM);
memset(new_psw,0,PSW_BITNUM);
lcd1602_show_string(10,1," ");//清除密码输入数据
}
//确认
else if(key==15)
{
beep_alarm(100,10);//提示音
cnt=0;
sys_str.psw_ok=0;//密码匹配成功标志清零,等待下次匹配
//第1次确认
if(tim==0)
{
//初始密码匹配
if(memcmp(sys_str.psw,sys_str.save_psw[0],PSW_BITNUM)==0)
sys_str.psw_ok=1;//有匹配的密码
}
else if(tim==1)
sys_str.psw_ok=1;//有匹配的密码
//第2次确认
else if(tim==2)
{
//新密码匹配
if(memcmp(sys_str.psw,new_psw,PSW_BITNUM)==0)
sys_str.psw_ok=1;//有匹配的密码
}
//密码错误
if(sys_str.psw_ok==0)//密码匹配错误
{
init_psw_error_show();//输入初始密码错误
delay_ms(2000);
return ;
}
//密码正确
else
{
if(tim==0)
new_psw_show();//请输入最新密码
else if(tim==1)
new_psw_once_show();//请再次输入最新密码
else if(tim==2)
{
psw_modify_ok_show();//重置密码成功
tim=0;
strcpy(sys_str.save_psw[0],new_psw);
//存储用户密码
for(i=0;i<PSW_BITNUM;i++)
{
at24c02_write_one_byte(i,sys_str.save_psw[0][i]);
}
delay_ms(2000);
return ;
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于51单片机的密码锁系统
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共49个文件
obj:10个
c:10个
lst:10个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 10 0 下载量 191 浏览量
2022-07-08
21:45:15
上传
评论
收藏 123KB ZIP 举报
温馨提示
对于初学者,作为课程设计完全足够,毕设的话需要调试自己的风格,而且其中的步进电机需要自己去购买
资源详情
资源评论
资源推荐
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 49 条
- 1
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
qq_1234560
- 粉丝: 9
- 资源: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0