仿真文件和完好源码下载地址: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_add(mima_3,0x00,6); //把修正的暗码存进24C02delay_ms(2000);flag_change = 0;}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; //3次输入暗码不正确报警while(i--)baoj();}flag_change = 0;}}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; //3次输入暗码不正确报警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);flag_change = 0;aa++;if(aa == 4){aa = 0;i = 20; //3次输入暗码不正确报警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; //3次输入暗码不正确报警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; //3次输入暗码不正确报警while(i--)baoj();}} }}/*外部中止函数,康复出厂设置,长按set键康复*/void int0() interrupt 0{delay_ms(2000);if(!set){lcd_pos(0,0);write_com(0x0c); //关光标write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显现清零,数据指针清零i2cinit();//24C02总线初始化write_n_add(mima_5,0x00,6);write_n_char("password renew");lcd_pos(1,0);write_n_char("already");delay_ms(1000);lcd_pos(0,0);write_com(0x0c); //关光标write_com(0x06);//写一个字符后地址指针加 1 write_com(0x01);//显现清零,数据指针清零write_n_char("Input password");lcd_pos(1,0);write_n_char("Press key A");}// 引起了三个正告}void timer0() interrupt 1 //守时器0中止,50ms守时{TH0 = 0x4c;//50ms守时TL0 = 0x00;bb++;if(bb == 200)//10秒时刻到{bb = 0;flag_t0 = 0;}}void main(){yjinit();//液晶初始化i2cinit();//24C02总线初始化baojing = 0;lock = 1; //关锁TMOD = 0x01;//挑选守时器0方法1EA = 1;//翻开总中止ET0 = 1;//翻开守时器0中止EX0 = 1; //翻开外部中止0IT0 = 1;//下降沿触发TR0 = 0;//封闭守时器TH0 = 0x4c;//50ms装初值TL0 = 0x00;while(1){mimachuli(); }}