module kmkm(cipher_in,count,warn_en,rst,am_en);
input rst,am_en; //定义输入变量:
am_en.密码设置键
input [3:0]cipher_in; //定义输入变量: 4 位密码output warn_en;//定义输出变量,警告output[1:0]count;//定义计数
reg warn_en;//定义警告为reg 型变量reg[1:0]state,state_out;//reg型2位变量reg[1:0]count;//reg型2位变量reg[3:0]amend_cipher;//reg型4位变量
parameter s0=2'b00,//定义参数的值,通过计时寄存器s1=2'b01,//s0-s3代表输入密码错误的次数s2=2'b10,s3=2'b11;
integer i;//定义有符号位变量
always@(cipher_in or posedge rst)//置位模块if(rst) begin//rst为1,进行复位state<=0;//将state重置为0warn_en<=0;//将warn_ en重置为0
count<=0;//将count重置为0
amend_cipher<=0;//将
amend_ _cipher重置为 0i<=0;//将i重置为0
endelse if(!am_en) begin//if(rst)为0,再判断初始密码am_ encase(state_out)
s0:if(cipher_in==amend_cipher) begin//判断键入密码是否等于初始密码,执行下列程序
count<=1;//相同,count+1, 密码正确
warn_en<=0;//输入密码正确,警报不累计
end else state<=s1; //state=1,输入错误s1:if(cipher_in== amend_cipher)
begin//判断第二次键入密码是否等于初始密码,执行下列程序
count<=i;//相同,count=i, 密码正确
warn_en<=0;//输入密码正确,警报不累计
end elsestate<=s2;//第二位输入密码错误s2:if(cipher_in==amend_cipher) begin//判断第三次输入密码是否等于初始密码,执行下列程序count<=i; //相同,
count=i, 密码正确
warn_en<=0;//输入密码正确,警报不累计end elsestate<=s3;//第三位密码错误s3:beginwarn_en<=1;//警报此时为1state<=s3;//密码输错3次end//结束if 循环嵌套default: state<=s0;//否则次数为0, 即0次endcaseend//结束if 循环嵌套endmodule
input rst,am_en; //定义输入变量:
am_en.密码设置键
input [3:0]cipher_in; //定义输入变量: 4 位密码output warn_en;//定义输出变量,警告output[1:0]count;//定义计数
reg warn_en;//定义警告为reg 型变量reg[1:0]state,state_out;//reg型2位变量reg[1:0]count;//reg型2位变量reg[3:0]amend_cipher;//reg型4位变量
parameter s0=2'b00,//定义参数的值,通过计时寄存器s1=2'b01,//s0-s3代表输入密码错误的次数s2=2'b10,s3=2'b11;
integer i;//定义有符号位变量
always@(cipher_in or posedge rst)//置位模块if(rst) begin//rst为1,进行复位state<=0;//将state重置为0warn_en<=0;//将warn_ en重置为0
count<=0;//将count重置为0
amend_cipher<=0;//将
amend_ _cipher重置为 0i<=0;//将i重置为0
endelse if(!am_en) begin//if(rst)为0,再判断初始密码am_ encase(state_out)
s0:if(cipher_in==amend_cipher) begin//判断键入密码是否等于初始密码,执行下列程序
count<=1;//相同,count+1, 密码正确
warn_en<=0;//输入密码正确,警报不累计
end else state<=s1; //state=1,输入错误s1:if(cipher_in== amend_cipher)
begin//判断第二次键入密码是否等于初始密码,执行下列程序
count<=i;//相同,count=i, 密码正确
warn_en<=0;//输入密码正确,警报不累计
end elsestate<=s2;//第二位输入密码错误s2:if(cipher_in==amend_cipher) begin//判断第三次输入密码是否等于初始密码,执行下列程序count<=i; //相同,
count=i, 密码正确
warn_en<=0;//输入密码正确,警报不累计end elsestate<=s3;//第三位密码错误s3:beginwarn_en<=1;//警报此时为1state<=s3;//密码输错3次end//结束if 循环嵌套default: state<=s0;//否则次数为0, 即0次endcaseend//结束if 循环嵌套endmodule
