---------------------------------------------------------- -- keyEncode -- Author : Gautam Karnik -- Date : March 30, 2001 -- Filename : keyEncode.vhd -- Architecture : Behavioral -- Description : This entity takes in the row and column -- value of the key that has been pressed -- and encodes the data for either user 1 -- or user 2. Each user can have data -- values from 0 to 7. ---------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; library work; use work.CDMA_pkg.all; entity keyEncode is port ( resetn : in std_logic; clock : in std_logic; row : in std_logic_vector ( 3 downto 0 ); col : in std_logic_vector ( 3 downto 0 ); usr1_data : out std_logic_vector ( 2 downto 0); usr2_data : out std_logic_vector ( 2 downto 0) ); end entity keyEncode; architecture behavioral of keyEncode is type KEY_TYPE is ( keyNone, key0, key1, key2, key3, key4, key5, key6, key7, key8, key9, key10, key11, key12, key13, key14, key15 ); signal key : KEY_TYPE; begin translate : process ( clock, resetn ) begin wait until rising_edge ( clock ); if (resetn = '0') then key <= keyNone; else -- Button numbers for the keypad -- 0 1 2 3 -- 4 5 6 7 -- 8 9 10 11 -- 12 13 14 15 CASE col IS WHEN "0001" => CASE row is WHEN "1110" => key <= key0; WHEN "1101" => key <= key4; WHEN "1011" => key <= key8; WHEN "0111" => key <= key12; WHEN OTHERS => key <= keyNone; END CASE; WHEN "0010" => CASE row is WHEN "1110" => key <= key1; WHEN "1101" => key <= key5; WHEN "1011" => key <= key9; WHEN "0111" => key <= key13; WHEN OTHERS => key <= keyNone; END CASE; WHEN "0100" => CASE row is WHEN "1110" => key <= key2; WHEN "1101" => key <= key6; WHEN "1011" => key <= key10; WHEN "0111" => key <= key14; WHEN OTHERS => key <= keyNone; END CASE; WHEN "1000" => CASE row is WHEN "1110" => key <= key3; WHEN "1101" => key <= key7; WHEN "1011" => key <= key11; WHEN "0111" => key <= key15; WHEN OTHERS => key <= keyNone; END CASE; WHEN OTHERS => key <= keyNone; END CASE; end if; end process translate; with key select usr1_data <= "000" when key0, "001" when key1, "010" when key2, "011" when key3, "100" when key4, "101" when key5, "110" when key6, "111" when key7, "000" when others; with key select usr2_data <= "000" when key8, "001" when key9, "010" when key10, "011" when key11, "100" when key12, "101" when key13, "110" when key14, "111" when key15, "000" when others; end behavioral;