资源描述:
《电子密码锁主程序》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include"reg51.h"#include"key.h"#include"AT24C02.h"#include"LCD_1602.h"#defineucharunsignedchar#defineuintunsignedintsbitOUT2=P3^1;sbitOUT1=P3^0;sbitread_key1=P3^2;sbitread_key2=P1^3;ucharkey_scan_en;ucharkey_buf;//***********************************************************//键扫描表ucharcodekey_scan_
2、tap[4]={0x10,0x20,0x40,0x80};ucharcodeLed_dsp_tap[7]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf};//键码表******************************************************ucharcodekey_tap[16]={0x4e,0x87,0x47,0x27,0x8b,0x4b,0x2b,0x8d,0x4d,0x2d,0x2e,0x8e,0x1e,0x1d,0x1b,0x17};ucharnew_key;ucharold_key;ucharkey_cont;uchark
3、ey;//********************************************ucharinput_cont;ucharinput_cont2;ucharinput_step;//********************************************ucharpassword[6];ucharinput_password[6];ucharinput_password2[6];chardsp_buf[6];ucharopen_en;ucharOUT_delay;ucharerr_cont;ucharstop_delay;ucharset_flg;ucha
4、rinput_time;structkey_flag{unsignedpassword_in:1;unsignedkeep:1;unsignedopen:1;unsignedredly_keep:1;unsignedcall_open:1;unsignedID_OK:1;unsignedcontrol_en:1;unsignedcontrol_input:1;}key_flag;structkey_flag2{unsignedpower_key:1;}key_flag2;//***************************************************externu
5、charsec;externucharbeef_cont;//***************************************************voidkey_control(void){uchari;if(set_flg==0){if(open_en){if((key<10)&&(err_cont<3)){if(input_cont<6){WRITE_ML(0x01);//清显示dsp_buf[input_cont]='*';lcd_dsp(0,0,"inputpassword",14);lcd_dsp(1,0,"password:",9);input_passwor
6、d[input_cont]=key;input_cont++;lcd_dsp(1,9,dsp_buf,input_cont);}}elseif(key==10)//确定键{if(input_cont==6){for(i=0;i<6;i++){if(input_password[i]!=password[i]){beef_cont=0x03;err_cont++;if(err_cont==3)stop_delay=60;WRITE_ML(0x01);//清显示lcd_dsp(0,0,"inputpassword",14);lcd_dsp(1,0,"password:",9);input_co
7、nt=0;i=7;}}if(i==6){WRITE_ML(0x01);//清显示lcd_dsp(0,0,"Success",7);sec=6;OUT_delay=5;input_cont=0;beef_cont=0x81;err_cont=0;open_en=0;}}}elseif(key==11)//取消键{if(input_cont>0){WRITE_ML(0x01);//清显示lcd_dsp(0,0,"inputp