VHDL Code for 7-Segment Display from HEX Keypad

This article provides VHDL source code for displaying characters on a 7-segment display, using input from a HEX keypad.

7 segment Display Image alt: 7 segment Display

VHDL Code

Here’s the VHDL code:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity key is
    Port (  col: inout std_logic_vector(3 downto 0):="0001";
            row : in std_logic_vector(3 downto 0);
            clk : in std_logic;
            disp_sel: out std_logic_vector(3 downto 0);
            ss : out std_logic_vector(6 downto 0));
end key;

architecture Behavioral of key is
begin
    process(clk) is
    begin
        if (rising_edge(clk)) then
            col <= col(2 downto 0) & col(3);
        end if;
    end process;

    disp_sel <= "1110";

    process(col,row)
    begin
        case (col) is
            when "0001" =>
                case row is
                    when "0001" => ss <= "1111110";
                    when "0010" => ss <= "0110011";
                    when "0100" => ss <= "1111111";
                    when "1000" => ss <= "1001110";
                    when others=> ss <= "0000000";
                end case;
            when "0010" =>
                case (row) is
                    when "0001" => ss <= "0110000";
                    when "0010" => ss <= "1011011";
                    when "0100" => ss <= "1111011";
                    when "1000" => ss <= "0111101";
                    when others=> ss <= "0000000";
                end case;
            when "0100" =>
                case (row )is
                    when "0001" => ss <= "1101101";
                    when "0010" => ss <= "1011111";
                    when "0100" => ss <= "1110111";
                    when "1000" => ss <= "1001111";
                    when others=> ss <= "0000000";
                end case;
            when "1000" =>
                case (row)is
                    when "0001" => ss <= "1111001";
                    when "0010" => ss <= "1110000";
                    when "0100" => ss <= "0011111";
                    when "1000" => ss <= "1000111";
                    when others=> ss <= "0000000";
                end case;
            when others=> null;
        end case;
    end process;

end behavioral;