单片机电子密码锁程序(2)
时间:11-30
来源:互联网
点击:
仿真文件和完整源码下载地址:http://www.51hei.com/bbs/dpj-22586-1.html
论文下载地址:http://www.51hei.com/f/电子密码锁论文最终稿.docx
下面是main.c文件:
#include#include "delay_ms.h"#include "矩阵键盘.h"#include "i2c.h"#include "1602.h"#include "delay_ms.h"#include "mima.h"#define uchar unsigned char#define uint unsigned int#define A 0x0a //输入密码#define B 0x0b //修改密码#define D 0x0d //关锁#define enter 0x0c //确认#define backspace 0x0f //退格键sbit baojing = P3^7; //蜂鸣器接口sbit lock = P3^3;//锁信号sbit set = P3^2;uchar idata mima_5[6] = {1,2,3,4,5,6}; //初始密码uchar flag_change; uchar aa;//存放密码错误的次数,够三次报警uchar bb;uchar flag_t0;void baoj1()//报警函数{int i;for(i = 0;i < 5; i++){baojing = 1;delay_ms(5);baojing = 0;delay_ms(5); }}void baoj(){uchar i;for(i = 0; i < 10; i++)baoj1();}/*密码处理函数*/void mimachuli() {uchar key,i;uchar idata mima_1[6]={ , , , , , };//存放密码缓冲区uchar idata mima_2[6]={ , , , , , };uchar idata mima_3[6]={ , , , , , };key = step_choose();if(key == A)//A被按下,接收输入密码,处理{read_n_add(mima_1,0x00,6);write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_com(0x0f);//显示光标lcd_pos(0,0);write_n_char(" press password "); if(input_mima(mima_2)) //处理输入密码{if(mimaduibi(mima_2,mima_1)) //密码正确{lcd_pos(0,0);write_com(0x0c);write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_n_char(" password right ");aa = 0; //清除密码错误次数lock = 0; //开锁baojing = 1; //响一下delay_ms(1000);baojing = 0;TR0 = 1;flag_t0 = 1;while(key != D && flag_t0) //D没按下一直开{ key = keyscan();}TR0 = 0;lock = 1;//D按下了关锁}else //密码 不正确{lcd_pos(0,0);write_com(0x0c); //关光标write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_n_char(" password wrong");delay_ms(1000);aa++;if(aa == 4){aa = 0;i = 20; //密码不正确报警while(i--)baoj();}}}else //密码没有输入正确或完成{lcd_pos(0,0);write_com(0x0c); //关光标write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_n_char(" password wrong");delay_ms(1000);aa++;if(aa == 4){aa = 0;i = 20; //密码不正确报警while(i--)baoj();}}}if(key == B)//B被按下,修改密码{read_n_add(mima_1,0x00,6);write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_com(0x0f);//显示光标lcd_pos(0,0);write_n_char(" input password"); write_com(0x0f);//显示光标 if(input_mima(mima_2)) //处理输入密码{if(mimaduibi(mima_2,mima_1)) //密码正确{lcd_pos(0,0);write_com(0x0c);write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_n_char("password right ");aa = 0; //清除密码错误次数delay_ms(1500);flag_change = 1;while(flag_change) //下面开始修改密码{write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_com(0x0f);//显示光标lcd_pos(0,0);write_n_char("In new password");delay_ms(1500);if(input_mima(mima_2)) //处理输入密码{lcd_pos(0,0);write_com(0x0c);write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_n_char("Input new pass"); //确定新密码lcd_pos(1,0);write_n_char("word again");delay_ms(2000);lcd_pos(0,0);write_com(0x0f);//显示光标write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_n_char("In new password"); if(input_mima(mima_3)) //处理输入密码{if(mimaduibi(mima_2,mima_3)) //密码正确{lcd_pos(0,0);write_com(0x0c);write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显示清零,数据指针清零write_n_char("password has");lcd_pos(1,0);write_n_char("change already");write_n_a
单片机电子密码 相关文章:
- 单片机电子密码锁子程序(11-30)
- 一种简单51单片机电子密码锁设计(11-21)
- 单片机实现电子密码锁(11-18)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)