资源描述:
《基于fpga的数字密码锁(使用矩阵键盘).doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、......基于FPGA数字密码锁板子使用的是DE2顶层topmodulelock(reset,clk,row,col,mm0,mm1,mm2,mm3,led1,led2,led3,set_flog);inputclk,reset;input[3:0]row;outputwire[3:0]col;outputwire[6:0]mm0,mm1,mm2,mm3;outputregled1,led2,led3;wire[3:0]key_value;reg[3:0]temp_key;reg[3:0]m0,m1,m2,m3;reg[3:0]m_0,m_1,m_2,m_
2、3;reg[5:0]state;reg[2:0]wei;wirekey_valid;reg[1:0]count_wrong;outputregset_flog;parametervalid=6'b000000,set=6'b000001,.专业.专注.......collection_mm=6'b000010,cmd=6'b000100,collection=6'b001000,wrong=6'b010000,correct=6'b100000,die_lock=6'b000011,lock=6'b000111;always@(posedgeclkorneg
3、edgereset)beginif(!reset)beginstate<=6'b000000;wei<=0;led3<=0;set_flog<=0;led1<=0;led2<=0;m0<=15;m1<=15;m2<=15;m3<=15;endelsebegincase(state)valid:if(key_valid).专业.专注.......begintemp_key<=key_value;state<=collection;endelsestate<=valid;collection:beginif(key_value>=0&&key_value<=9)
4、beginif(led1&&(!set_flog))//开启状态不能按数字键state<=valid;elseif((!key_valid)&&(wei<5))beginled2<=0;state<=collection_mm;wei<=wei+1'b1;endelsestate<=collection;endelse.专业.专注.......if(!key_valid)state<=cmd;endcollection_mm:begincase(wei)1:m0<=temp_key;2:m1<=temp_key;3:m2<=temp_key;4:m3<=te
5、mp_key;endcasestate<=valid;endcmd:begincase(temp_key)15:if(!led1)beginm0<=15;m1<=15;m2<=15;m3<=15;//*clear.专业.专注.......state<=valid;wei<=0;led2<=0;led1<=0;endelsestate<=valid;14:if(led1)state<=valid;elseif(wei)//backdeletebegincase(wei)1:m0<=15;2:m1<=15;3:m2<=15;4:m3<=15;endcasewei
6、<=wei-1'b1;state<=valid;led2<=0;endelse.专业.专注.......state<=valid;13:if(set_flog)//保存密码beginset_flog<=0;led1<=0;m_0<=m0;m_1<=m1;m_2<=m2;m_3<=m3;state<=lock;endelseif((m0==m_0)&&(m1==m_1)&&(m2==m_2)&&(m3==m_3))//comparebeginstate<=correct;m0<=15;m1<=15;m2<=15;m3<=15;endelsebeginstate
7、<=wrong;count_wrong<=count_wrong+1;end.专业.专注.......12:state<=lock;10:if(led1)//setbeginset_flog<=1;wei<=0;m0<=15;m1<=15;m2<=15;m3<=15;state<=valid;enddefault:state<=valid;endcaseendcorrect:begin//openled1<=1;state<=valid;count_wrong<=0;endwrong:beginled2<=1;state<=valid;led1<=0;if(
8、count_wrong==3)//lockdiebe