-- code for checking the password entered using a keypad which gives binary outputs library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; use ieee.numeric_std.all; -- defining the entity entity PASSCHECK is port( IN1 : in std_logic_vector( 3 downto 0); CLK : in std_logic; OUT1,OUT2 : out std_logic); end PASSCHECK; -- IN1 is for the inputs for the password -- architecture of the code for checking the password architecture behavioral of PASSCHECK is type PASS_WORD is array ( 0 to 3 ) of integer range 0 to 12; constant PASSWORD : PASS_WORD := (1,2,3,4); -- the correct password with the first integer on the left most side signal COUNT1, COUNT2 : integer range 0 to 5; signal temp : integer range 0 to 12; signal MC : integer range 0 to 50000; signal DCLK : std_logic; -- --component NIB_TO_INT is --port( IN1 : in std_logic_vector( 3 downto 0); -- OUT1,OUT2 : out integer range 0 to 9); --end component; --OUT1<='0'; --OUT2<='0'; begin --COUNT1 is used to check if any botton is pressed, its value is 1 if any of the buttons is pressed. --COUNT2 checks the number of correctly entered integers, its value changes to 5 if any of the integer entered is wrong. process(CLK) begin if CLK'event and CLK = '1' then if(MC = 500) then DCLK <= not DCLK; MC <= 0; else MC <= MC +1; end if; end if; end process; process (IN1) begin case IN1 is when "0000" => temp <= 0; when "0001" => temp <= 1; when "0010" => temp <= 2; when "0011" => temp <= 3; when "0100" => temp <= 4; when "0101" => temp <= 5; when "0110" => temp <= 6; when "0111" => temp <= 7; when "1000" => temp <= 8; when "1001" => temp <= 9; when "1010" => temp <= 10; when "1011" => temp <= 11; when "1100" => temp <= 12; when others=> temp <=10; --since 12 refers to clear the screen end case; end process; PROCESS(temp,DCLK) begin if(DCLK'event and DCLK = '0' ) then if(temp /= 0) then -- if(COUNT1 = 0) then COUNT1 <= 1; if(temp = 12 )then -- 12 is the enter key if(COUNT2 = 4) then -- if all the data is correctly entered OUT1 <= '1'; --signal for correct value OUT2 <= '0'; --COUNT1 <= 0; --initialise for the next time --COUNT2 <= 0; else OUT2 <= '1'; -- if wrong data was interted then out2 becomes high OUT1 <= '0'; COUNT1 <= 0; COUNT2 <= 0; end if; elsif(temp =10 )then --10 is the clear button which would clear the screen/memory COUNT2 <= 0; COUNT1 <= 0; OUT1 <= '0'; OUT2 <= '0'; end if; if(COUNT2 < 4) then -- checkig each data if(temp = PASSWORD(COUNT2)) then COUNT2 <= COUNT2 +1; else COUNT2 <= 5; -- if wrong data is enterd then the vlue of count2 becomes 5 ie. wrong password end if; end if; -- end if; elsif(temp = 0) then --either waiting for next input or just on standby if(COUNT1 = 1) then COUNT1 <= 0; --ready to take next input end if; end if; end if; end process; end behavioral;