library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; entity digital_lock is Port ( my_btnC, clk, my_btnU, my_btnR, my_btnL, my_btnD: in std_logic; my_sw: in std_logic_vector(3 downto 0); hex0, hex1, hex2, hex3: out std_logic_vector (3 downto 0); my_led: out std_logic_vector(15 downto 0) ); end digital_lock; architecture Behavioral of digital_lock is type state IS (s0, s1, s2, s3, s4 ,s5 ,s6, s7, s8, s9, s10,s11); signal my_state: state; signal my_status: unsigned(1 downto 0); signal num1, num2, num3, key1, key2, key3: std_logic_vector(3 downto 0); signal number, final_key: std_logic_vector(11 downto 0); begin FSM: process(clk, my_btnC) begin if(my_btnC ='1') then my_state <= s0; elsif rising_edge(clk) then case my_state is when s0 => my_status <= "00"; my_led <= "1100000000000000"; hex3 <= "0000"; hex2 <= "0000"; hex1 <= "0000"; hex0 <= "0000"; if(my_btnL ='1') then my_state <= s1; else my_state <= s0; end if; when s1 => key1 <= my_sw; hex0 <= key1; my_led <= "0000000000000001"; if(my_btnL='1') then my_state <= s2; else my_state <= s1; end if; when s2 => key2 <= my_sw; hex0 <= key2; my_led <= "0000000000000010"; if(my_btnL ='1') then my_state <= s3; else my_state <= s2; end if; when s3 => key3 <= my_sw; hex0 <= key3; my_led <= "0000000000000011"; if(my_btnR= '1') then my_state <= s4; else my_state <= s3; end if; when s4 => final_key(11 downto 8) <= key1; final_key(7 downto 4) <= key2; final_key(3 downto 0) <= key3; my_led <= "0000000000000100"; if(my_btnU ='1') then my_state <= s5; else my_state <= s4; end if; when s5 => num1 <= my_sw; hex0 <= num1; my_led <= "0000000000000101"; if(my_btnD ='1') then my_state <= s0; elsif (my_btnL ='1') then my_state <= s6; else my_state <= s5; end if; when s6 => num2 <= my_sw; hex0 <= num2; my_led <= "0000000000000110"; if(my_btnD ='1') then my_state <= s0; elsif(my_btnL ='1') then my_state <= s7; else my_state <= s6; end if; when s7 => num3 <= my_sw; hex0 <= num3; my_led <= "0000000000000111"; if(my_btnD ='1') then my_state <= s0; elsif(my_btnR = '1') then my_state <= s8; else my_state <= s7; end if; when s8 => number(11 downto 8) <= num1; number(7 downto 4) <= num2; number(3 downto 0) <= num3; my_led <= "0000000000001000"; if(number = final_key) then my_state <= s9; else my_state <= s10; end if; when s9 => my_led <= "1111111111111111"; if(my_btnD = '1') then my_state <= s0; else my_state <= s9; end if; when s10 => my_status <= my_status + 1; if(my_status >= 3) then my_state <= s11; elsif(my_status < 3) then my_state <= s5; end if; when s11 => my_led <= "0000000000000000"; hex0 <= "1111"; hex1 <= "1111"; hex2 <= "1111"; hex3 <= "1111"; my_state <= s11; end case; end if; end process; end Behavioral;