微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机电子密码锁程序(2)

单片机电子密码锁程序(2)

时间:11-30 来源:互联网 点击:

for(x=z;x>

for(y=110;y>

gain");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(); }}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top