library IEEE; use IEEE.std_logic_1164.all; use work.password_get_package.all; entity password is port( clk : in std_logic; key_input : in std_logic_vector(7 downto 0); --input (password) from keypad key_get : in std_logic_vector(1 downto 0); enter : in std_logic; clear : in std_logic; reset_get : in std_logic; --singal from main logic to reset pass_ok signal to 0 program : in std_logic; --signal to enter program mode key_output : out std_logic_vector(7 downto 0); pass_ok : out std_logic --0 correct password not entered, 1 password ok (signal to main logic) ); end password; architecture behaviour of password is signal pass_state : std_logic_vector(2 downto 0); --signal key_input : std_logic_vector(8 downto 0); signal current_pass : std_logic_vector(7 downto 0); -- 000 pass not entered -- 001 pass ented ok -- 010 invalid password entered -- 011 programming state -- 100 programming state2 begin --initialize start state password_get_em: password_get port map(clk,key_get,clear,key_output); process (clk) begin if clk'EVENT and clk='1' then --pass_ok<='0'; --pass_state<="000"; --go to correct password state if pass_state="000" and key_input=current_pass and enter='1' and clear='0' then pass_state<="001"; pass_ok<='1'; --return to idle state 000 elsif pass_state="001" and reset_get='1' then --if reset_get='1' then pass_state<="000"; pass_ok<='0'; --go to incorrect password state elsif pass_state="000" and key_input /= current_pass and enter='1' then pass_state<="010"; --go to idle state from invalid password state elsif pass_state="010" and clear='1' then pass_state<="000"; pass_ok<='0'; --go to programming state elsif pass_state="000" and program='1' then pass_state<="011"; --enter current password then press enter elsif pass_state="011" and key_input = current_pass and enter='1' and clear='0' then pass_state<="100"; --set new password, return to idle state elsif pass_state="100" and clear='1' and enter='1' then current_pass<=key_input; pass_state<="000"; --cancel programming return to idle state elsif (pass_state="100" or pass_state="001") and enter='0' and clear='1' then pass_state<="000"; end if; end if; end process; end behaviour;