Four-bit password lock * Electronic password lock design

Source: Internet
Author: User

Note: The download must be accompanied by the original website, with the name of the author, thank you.
Four-bit password lock big experiment:


Function:

Title: Design of electronic cipher lock

[design requirements]

(1) Design a lock password of at least 4 digits (or more) password locks.

(2) When the unlock button switch (can be set 8 or more, where only 4 are valid, the remaining bit is fake) the input code is equal to the password set to start the lock control circuit, and with a green light, red light out of the unlocked state.

(3) From the first button after the touch of 5 seconds if the lock can not be opened, the circuit automatically reset and issued an alarm signal, at the same time with a green light, red light indicates the unlock state.

Additional features :

(1) You can set a password by setting the password button SP (S4) setting, and you can reset the new password. You can set the password in any case by pressing the SP after entering.

(2) The countdown of five seconds is displayed on the seven-segment digital tube of the Development Board. Alarm (green light) after five seconds.

(3) The number of times the key input password can be recorded (0-9).

(4) can clear 0 input times without changing the password.


Code:

Module index (Input CLK, input pw_1, input pw_2, input pw_3, input pw_4, input pw_5, input pw_6, input pw_7, input pw_8, Input sti_0, input sti_1, input sti_2, output x, output y, output reg red, output reg Green, output reg Alarm, out Put Reg Num0_1, output reg Num0_2, output reg Num0_3, output reg Num0_4, output reg Num0_5, output reg Num0_6, output  Reg Num0_7, Output reg Num0_8, output reg Num1_1, output reg Num1_2, output reg num1_3, output reg Num1_4, output
	Reg Num1_5, Output reg num1_6, output reg num1_7, output reg Num1_8); /* * Clk:clock * Pw:password * sti:stimulation * red/green:output LED * Num:nixie * */Reg Ctr
    L
	Reg CC;
	assign x = 1;
    Assign y = 1;
        Initial begin cc <= 1 ' b0;
        Alarm <= 1 ' b0;
        CTRL <= 1 ' B0;
        Red <= 1 ' B1;
        Green <= 1 ' b0;
        Num0_1 <= 1 ' B1;
        Num0_2 <= 1 ' B1;
        Num0_3 <= 1 ' B1;
        Num0_4 <= 1 ' B1; Num0_5 <=1 ' B1;
        Num0_6 <= 1 ' B1;
        Num0_8 <= 1 ' B1;
        Num1_1 <= 1 ' B1;
        Num1_2 <= 1 ' b0;
        Num1_3 <= 1 ' B1;
        Num1_4 <= 1 ' B1;
        Num1_5 <= 1 ' b0;
        Num1_6 <= 1 ' B1;
    Num1_7 <= 1 ' B1;
	End//CLK-divider reg CLK;
	Parameter N = 20000000;
	reg [31:0]ip;

	reg [31:0]IPR;
        Always @ (Posedge CLK) begin if (IP < N/2) begin IP <= IP + 1;
            End ELSE begin CLK <= ~CLK;
        IP <= ' B0;
    End end//Set password Reg Str_0, str_1, str_2, str_3;
    Reg In_0, in_1, in_2, in_3; Reg IN__;
    Reg Vtrl;

    Integer count = 0;
    Timer integer timer = 5;
        Always @ (Posedge CLK) begin if (sti_2 = = 1 ' b1) begin CTRL <= 1 ' B1;
        End in__ <= sti_1;
                Case (count) 0:begin num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' B1; Num0_4 < = 1 ' B1;
                Num0_5 <= 1 ' B1;
                Num0_6 <= 1 ' B1;
            Num0_7 <= 1 ' b0;
                End 1:begin num0_1 <= 1 ' b0;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' b0;;
                Num0_5 <= 1 ' b0;
                Num0_6 <= 1 ' b0;
            Num0_7 <= 1 ' b0;
                End 2:begin num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' b0;
                Num0_4 <= 1 ' B1;
                Num0_5 <= 1 ' B1;
                Num0_6 <= 1 ' b0;
            Num0_7 <= 1 ' B1;
                End 3:begin num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' B1;
                Num0_5 <= 1 ' b0;
                Num0_6 <= 1 ' b0;
            Num0_7 <= 1 ' B1;
  End 4:begin              Num0_1 <= 1 ' b0;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' b0;
                Num0_5 <= 1 ' b0;
                Num0_6 <= 1 ' B1;
            Num0_7 <= 1 ' B1;
                End 5:begin num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' b0;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' B1;
                Num0_5 <= 1 ' b0;
                Num0_6 <= 1 ' B1;
            Num0_7 <= 1 ' B1;
                End 6:begin num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' b0;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' B1;
                Num0_5 <= 1 ' B1;
                Num0_6 <= 1 ' B1;
            Num0_7 <= 1 ' B1;
                End 7:begin num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' b0;Num0_5 <= 1 ' b0;
                Num0_6 <= 1 ' b0;
            Num0_7 <= 1 ' b0;
                End 8:begin num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' B1;
                Num0_5 <= 1 ' B1;
                Num0_6 <= 1 ' B1;
            Num0_7 <= 1 ' B1;
                End 9:begin num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' B1;
                Num0_5 <= 1 ' b0;
                Num0_6 <= 1 ' B1;
            Num0_7 <= 1 ' B1;
                End Endcase if (sti_2 = = 1 ' B1) begin in_0 <= pw_5;
                In_1 <= pw_6;
                In_2 <= pw_7;
                In_3 <= Pw_8; 
        if (pw_1 = = 1 ' B1 && in_0 = = Str_0 && in_1 = str_1 && in_2 = str_2 && in_3 = str_3) begin        if (cc = = 1 ' b0) begin count <= count;
                CC <= 1 ' B1;
                End ELSE begin count <= count + 1;
                    End Green <= 1 ' B1;
                    Red <= 1 ' b0;
                Alarm <= 1 ' b0;
                    End else if (pw_1 = = 1 ' b1 && (in_0! = Str_0 | | in_1! = str_1 | | in_2! = str_2 | | in_3! = str_3)) begin
                        if (cc = = 1 ' b0) begin count <= count;
                    CC <= 1 ' B1;
                    End ELSE begin count <= Count +1; End end Else if (pw_1 = = 1 ' b0) begin if (in_0 = = Str_0 && in_1 = str_1 &&am P  In_2 = = Str_2 && in_3 = = str_3) begin if (cc = = 1 ' b0) begin Count <=
                        Count
                    CC <= 1 ' B1; End ElSE begin count <= count +1;
                        End Green <= 1 ' B1;
                        Red <= 1 ' b0;
                    Alarm <= 1 ' b0;
                End Count <= count;
                    End if (count = = 9) begin alarm <= 1 ' B1;
                    Red <= 1 ' B1;
                Green <= 1 ' b0; End End if (pw_1 = = 1 ' B1) begin case (timer) 0:begin num1_1 <= 1 '
               B1;
               Num1_2 <= 1 ' B1;
               Num1_3 <= 1 ' B1;
               Num1_4 <= 1 ' B1;
               Num1_5 <= 1 ' B1;
               Num1_6 <= 1 ' B1;
            Num1_7 <= 1 ' b0;
               End 1:begin num1_1 <= 1 ' b0;
               Num1_2 <= 1 ' B1;
               Num1_3 <= 1 ' B1;
               Num1_4 <= 1 ' b0;
           Num1_5 <= 1 ' b0;    Num1_6 <= 1 ' b0;
            Num1_7 <= 1 ' b0;
               End 2:begin num1_1 <= 1 ' B1;
               Num1_2 <= 1 ' B1;
               Num1_3 <= 1 ' b0;
               Num1_4 <= 1 ' B1;
               Num1_5 <= 1 ' B1;
               Num1_6 <= 1 ' b0;
            Num1_7 <= 1 ' B1;
               End 3:begin num1_1 <= 1 ' B1;
               Num1_2 <= 1 ' B1;
               Num1_3 <= 1 ' B1;
               Num1_4 <= 1 ' B1;
               Num1_5 <= 1 ' b0;
               Num1_6 <= 1 ' b0;
            Num1_7 <= 1 ' B1;
               End 4:begin num1_1 <= 1 ' b0;
               Num1_2 <= 1 ' B1;
               Num1_3 <= 1 ' B1;
               Num1_4 <= 1 ' b0;
               Num1_5 <= 1 ' b0;
               Num1_6 <= 1 ' B1;
            Num1_7 <= 1 ' B1;
               End 5:begin num1_1 <= 1 ' B1;
             Num1_2 <= 1 ' b0;  Num1_3 <= 1 ' B1;
               Num1_4 <= 1 ' B1;
               Num1_5 <= 1 ' b0;
               Num1_6 <= 1 ' B1;
            Num1_7 <= 1 ' B1; End Endcase if (in_0 = = Str_0 && in_1 = = str_1 && in_2 = str_2 && In_3 = =
                str_3) begin timer <= timer;
                Red <= 1 ' b0;
            Green <= 1 ' B1;
                End ELSE if (IPR < 5) begin timer <= timer;
                Red <= 1 ' B1;
                Green <= 1 ' b0;
            IPR <= IPR + 1;
                End else if (IPR = = 5 && Ctrl = 1 ' B1) begin timer <= timer-1;
                Red <= 1 ' B1;
                Green <= 1 ' b0;
            IPR <= 0;
                End if (timer = = 0) begin Red <= 1 ' B1;
                Green <= 1 ' b0;
            Alarm <= 1 ' B1; End end ELSE BEGIN timer <= 5;
                End if (in__ = = 1 ' b1) begin timer <= 5;
                In_0 <= 0;
                in_1 <= 0;
                In_2 <= 0;
                In_3 <= 0;
                Count <= 4 ' b0000;
                CTRL = 1 ' B0;
                Green <= 1 ' b0;
                CC <= 1 ' b0;
                Alarm <= 1 ' b0;
                Red <= 1 ' B1;
                Num0_1 <= 1 ' B1;
                Num0_2 <= 1 ' B1;
                Num0_3 <= 1 ' B1;
                Num0_4 <= 1 ' B1;
                Num0_5 <= 1 ' B1;
                Num0_6 <= 1 ' B1;
                Num0_7 <= 1 ' b0;
                Num1_1 <= 1 ' B1;
                Num1_2 <= 1 ' b0;
                Num1_3 <= 1 ' B1;
                Num1_4 <= 1 ' B1;
                Num1_5 <= 1 ' b0;
                Num1_6 <= 1 ' B1;
        Num1_7 <= 1 ' B1;
                End if (sti_0 = = 1 ' B1) begin str_0 <= pw_5;
       str_1 <= pw_6;         Str_2 <= pw_7;
        Str_3 <= Pw_8;

 End End Endmodule

PIN Bindings:

Set_property Iostandard LVCMOS33 [get_ports Alarm]
Set_property Iostandard LVCMOS33 [Get_ports CLK]
Set_property iostandard LVCMOS33 [Get_ports Green]
Set_property Iostandard LVCMOS33 [Get_ports num0_1]
Set_property Iostandard LVCMOS33 [Get_ports num0_2]
Set_property Iostandard LVCMOS33 [Get_ports Num0_3]
Set_property Iostandard LVCMOS33 [Get_ports Num0_4]
Set_property Iostandard LVCMOS33 [Get_ports num0_5]
Set_property Iostandard LVCMOS33 [Get_ports Num0_6]
Set_property Iostandard LVCMOS33 [Get_ports num0_7]
Set_property Iostandard LVCMOS33 [Get_ports Num0_8]
Set_property Iostandard LVCMOS33 [Get_ports num1_1]
Set_property Iostandard LVCMOS33 [Get_ports num1_3]
Set_property Iostandard LVCMOS33 [Get_ports num1_2]
Set_property Iostandard LVCMOS33 [Get_ports num1_4]
Set_property Iostandard LVCMOS33 [Get_ports num1_5]
Set_property Iostandard LVCMOS33 [Get_ports pw_1]
Set_property Iostandard LVCMOS33 [Get_ports num1_7]
Set_property Iostandard LVCMOS33 [Get_ports num1_6]
Set_property Iostandard LVCMOS33 [Get_ports num1_8]
Set_property Iostandard LVCMOS33 [Get_ports pw_2]
Set_property Iostandard LVCMOS33 [Get_ports Pw_3]
Set_property Iostandard LVCMOS33 [Get_ports Pw_4]
Set_property Iostandard LVCMOS33 [Get_ports sti_2]
Set_property Iostandard LVCMOS33 [Get_ports sti_1]
Set_property iostandard LVCMOS33 [Get_ports Red]
Set_property Iostandard LVCMOS33 [Get_ports pw_8]
Set_property Iostandard LVCMOS33 [Get_ports sti_0]
Set_property Iostandard LVCMOS33 [Get_ports pw_6]
Set_property Iostandard LVCMOS33 [Get_ports pw_7]
Set_property Iostandard LVCMOS33 [Get_ports pw_5]
Set_property Package_pin K1 [get_ports Alarm]
Set_property package_pin H6 [Get_ports Green]
Set_property package_pin H5 [Get_ports Red]
Set_property package_pin B4 [Get_ports num0_1]
Set_property package_pin A4 [Get_ports num0_2]
Set_property package_pin A3 [Get_ports Num0_3]
Set_property package_pin B1 [Get_ports Num0_4]
Set_property package_pin A1 [Get_ports num0_5]
Set_property package_pin B3 [Get_ports Num0_6]
Set_property package_pin B2 [Get_ports num0_7]
Set_property package_pin D5 [Get_ports Num0_8]
Set_property package_pin D4 [Get_ports num1_1]
Set_property package_pin E3 [Get_ports num1_2]
Set_property package_pin D3 [Get_ports num1_3]
Set_property package_pin F4 [Get_ports num1_4]
Set_property package_pin F3 [Get_ports num1_5]
Set_property package_pin E2 [Get_ports num1_6]
Set_property package_pin D2 [Get_ports num1_7]
Set_property package_pin H2 [Get_ports num1_8]
Set_property package_pin P5 [Get_ports pw_1]
Set_property package_pin P4 [Get_ports pw_2]
Set_property package_pin P3 [Get_ports Pw_3]
Set_property package_pin P2 [Get_ports Pw_4]
Set_property package_pin R2 [Get_ports pw_5]
Set_property package_pin M4 [Get_ports pw_6]
Set_property package_pin N4 [Get_ports pw_7]
Set_property package_pin R1 [Get_ports pw_8]
Set_property package_pin U4 [Get_ports sti_0]
Set_property package_pin R17 [Get_ports sti_1]
Set_property package_pin R15 [get_ports sti_2] Set_property package_pin P17 [get_ports CLK] Set_property IOSTANDARD LVCMOS [Get_ports x]
Set_property Iostandard LVCMOS33 [Get_ports y]
Set_property Package_pin G2 [Get_ports x]
Set_property Package_pin G6 [Get_ports y]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.