This is a combination lock password module, but I can't into the keys of the keyboard input, the keyboard when I got the simulation for value (13), then enter the Numbers, but four password register is the same, have a great god help see
The module admin (CLK, key, p0, p1, p2, p3, boom, the error, flag);
The input CLK.
Input [3-0] key;//input keys
Input flag;
The output reg [3-0] p0, p1, p2, p3;//password temporary
The output reg boom, the error;
The parameter idle=4 'b0000;
The parameter s0=4 'b0001;
The parameter s1=4 'b0010;
The parameter s2=4 'b0011;
The parameter s3=4 'b0100;
The parameter check=4 'b0101;
The parameter boom0=4 'b0110;
The parameter error0=4 'b0111;
The parameter change0=4 'b1000;
The parameter change1=4 'b1001;
The parameter change2=4 'b1010;
The parameter change3=4 'b1011;
The parameter check0=4 'b1100;
Reg [3-0] m0, m1, m2, m3,//the old password
Reg [3-0] next_state;//time state
Reg [3-0] the current_state;//now state
Reg the set;//set the password said a
Reg [12:0] CNT;
Always @ (posedge CLK)
The begin
The current_state & lt;=next_state;
End
Always @ (posedge CLK)
The begin
Case (the current_state)
Idle://wait for
The begin
If (key==13)//prepare
The begin
Next_state & lt;=s0;
End
The else
The begin
Next_state & lt;=idle;
End
If (key==10) set password//
The begin
Set<=1;
Next_state & lt;=s0;
End
The else
The begin
Next_state & lt;=idle;
End
End
S0://the first password
The begin
If (key==0 | | key==1 | | key==2 | | key==| 3 | key==4 | | key==5 | | key==6 | | key==7 | | key==8 | | key==9)//keyboard digital key input symbol
The begin
P0 & lt;=the key;
Next_state & lt;=s1;
End
The else
The begin
Next_state & lt;=s0;
End
End
S1://the second password
The begin
If (key==0 | | key==1 | | key==2 | | key==| 3 | key==4 | | key==5 | | key==6 | | key==7 | | key==8 | | key==9)
The begin
P1 & lt;=the key;
Next_state & lt;=s2;
End
The else
The begin
Next_state & lt;=s1;
End
If (key==11)//backspace
The begin
P0 & lt;=4 'b0000;
Next_state & lt;=s0;
End
The else
The begin
Next_state & lt;=s1;
End
End
S2:
The begin
If (key==0 | | key==1 | | key==2 | | key==| 3 | key==4 | | key==5 | | key==6 | | key==7 | | key==8 | | key==9)
The begin
The p2 & lt;=the key;
Next_state & lt;=s3;
End
The else
The begin
Next_state & lt;=s2;
End
If (key==11)
The begin
P1 & lt;=4 'b0000;
Next_state & lt;=s1;
End
The else
The begin
Next_state & lt;=s2;
End
End
S3:
The begin
If (key==0 | | key==1 | | key==2 | | key==| 3 | key==4 | | key==5 | | key==6 | | key==7 | | key==8 | | key==9)
The begin
P3 & lt;=the key;
Next_state & lt;=check;
End
The else
The begin
Next_state & lt;=s3;
End
If (key==11)
The begin
The p2 & lt;=4 'b0000;
Next_state & lt;=s2;
End
The else
The begin
Next_state & lt;=s3;
End
End
Check/check/password
:The begin
If (key==11)
The begin
P3 & lt;=4 'b0000;
Next_state & lt;=s3;
End
The else
The begin
Next_state & lt;=check;
End
If (key==14)
The begin
If (m3==p3 & amp; & M2==p2 & amp; & M1==p1 & amp; & M0==p0)
The begin
If (set==1)//set to enter the password
The begin
Next_state & lt;=change0;
P0 & lt;=4 'b0000;
P1 & lt;=4 'b0000;
The p2 & lt;=4 'b0000;
P3 & lt;=4 'b0000;
Set<=0;
End
If (set==0)//not to enter the password set
The begin
Next_state & lt;=boom0;
P0 & lt;=4 'b0000;
P1 & lt;=4 'b0000;
The p2 & lt;=4 'b0000;
P3 & lt;=4 'b0000;
End
End
The else//password wrong
The begin
Next_state & lt;=error0;
P0 & lt;=4 'b0000;
P1 & lt;=4 'b0000;
The p2 & lt;=4 'b0000;
P3 & lt;=4 'b0000;
End
End
The else
The begin
Next_state & lt;=check;
End
End
Set password change0://the first
The begin
If (key==0 | | key==1 | | key==2 | | key==| 3 | key==4 | | key==5 | | key==6 | | key==7 | | key==8 | | key==9)
The begin
P0 & lt;=the key;
Next_state & lt;=change1;
End
The else
The begin
Next_state & lt;=change0;
End
End
Change1:
The begin
If (key==0 | | key==1 | | key==2 | | key==| 3 | key==4 | | key==5 | | key==6 | | key==7 | | key==8 | | key==9)
The begin
P1 & lt;=the key;
Next_state & lt;=change2;
End
The else
The begin
Next_state & lt;=change1;
End
If (key==11)
The begin
P0 & lt;=4 'b0000;
Next_state & lt;=change0;
End
The else
The begin
Next_state & lt;=change1;
End
End
Change2:
The begin
If (key==0 | | key==1 | | key==2 | | key==| 3 | key==4 | | key==5 | | key==6 | | key==7 | | key==8 | | key==9)
The begin
The p2 & lt;=the key;
Next_state & lt;=change3;
End
The else
The begin
Next_state & lt;=change2;
End
If (key==11)
The begin
P1 & lt;=4 'b0000;
Next_state & lt;=change1;
End
The else
The begin
Next_state & lt;=change2;
End
End
Change3:
The begin
If (key==0 | | key==1 | | key==2 | | key==| 3 | key==4 | | key==5 | | key==6 | | key==7 | | key==8 | | key==9)
The begin
P3 & lt;=the key;
Next_state & lt;=check0;
End
The else
The begin
Next_state & lt;=change3;
End
If (key==11)
The begin
The p2 & lt;=4 'b0000;
Next_state & lt;=change2;
End
The else
The begin
Next_state & lt;=change3;
End
End
Check0:
The begin
If (key==11)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull