-- keypush.vhd -- Christopher Kowalski -- EE 552 -- -- This code will output the value of a key on a keyboard after the key has been released. library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; package key_pack is component key is port(keyboard, reset, keyclock : in std_logic; scancode : out std_logic_vector(7 downto 0); gotcode : out std_logic); end component key; end package key_pack; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; library work; use work.key_pack.all; entity keypush is port(keyboard, clock, reset, keyread, keyclock : in std_logic; key_out : out std_logic_vector(7 downto 0); gotkey : out std_logic); end keypush; architecture structural of keypush is -- declare internal signals signal key_command : std_logic_vector(7 downto 0); signal key_done : std_logic; begin keyreader: component key port map(keyboard => keyboard, reset => reset, keyclock => keyclock, scancode => key_command, gotcode => key_done); getkey : process (clock) is --process variable variable step:natural range 0 to 3; begin if rising_edge(clock) then if reset = '1' then key_out <= (others => '0'); gotkey <= '0'; step:= 0; elsif (key_done = '1') and (key_command = "11110000") then --F0 is sent from the keyboard step:= 1; elsif (step = 1) and (key_done = '0') then -- wait until an other key is pressed step:= 2; elsif (step = 2) and (key_done = '1') then -- when the key has been read in register it. key_out <= key_command; gotkey <= '1'; step:= 3; elsif (step = 3) and (keyread = '1') then -- a handshaking signal. When your system has -- read the key assert a signal high to tell -- this code that you have read the key. key_out <= (others => '0'); -- clear the key value, you don't have to do this gotkey <= '0'; -- low this signal until a new key is detected step:= 0; end if; end if; end process getkey; -- NOTE: the key must be read by your system before the next key is released other wise the next -- key will be ignored. end structural;