LIBRARY ieee;
USE ieee.std_logic_1164. all;
USE ieee.numeric_std.all;
 
ENTITY segment_display IS
	PORT (
		CLK		:	IN std_logic;
		DIN		:	IN	std_logic_vector(15 DOWNTO 0);
		SEG		:	OUT std_logic_vector(6 DOWNTO 0);
		DISP	:	OUT std_logic_vector(3 DOWNTO 0)
	);
END segment_display;
 

ARCHITECTURE Behavioral OF segment_display IS

	SIGNAL iDISP	: unsigned(1 DOWNTO 0) := (OTHERS => '0');
	SIGNAL iData 	: std_logic_vector(3 DOWNTO 0) := (OTHERS => '0');

BEGIN
	
	PROCESS (CLK) IS
	VARIABLE cnt: unsigned(15 DOWNTO 0) := (OTHERS => '0');
	BEGIN
		IF rising_edge(CLK) THEN
			IF cnt(15) = '1' THEN
				cnt := (OTHERS => '0');
				iDISP <= iDISP + 1;
			ELSE
				cnt := cnt + 1;
			END IF;
		END IF;
	END PROCESS;
	
	iData <= DIN(3 DOWNTO 0)  WHEN iDISP = "00" ELSE
			 DIN(7 DOWNTO 4)  WHEN iDISP = "01" ELSE
			 DIN(11 DOWNTO 8) WHEN iDISP = "10" ELSE
			 DIN(15 DOWNTO 12);
			  
	DISP(0) <= '0' WHEN iDISP = "00" ELSE '1';
	DISP(1) <= '0' WHEN iDISP = "01" ELSE '1';
	DISP(2) <= '0' WHEN iDISP = "10" ELSE '1';
	DISP(3) <= '0' WHEN iDISP = "11" ELSE '1';

	WITH iData SELECT	  --"gfedcba"
    		SEG <= 			"1000000" WHEN "0000", -- symbol 0
							"1111001" WHEN "0001", -- symbol 1
							"0100100" WHEN "0010", -- symbol 2
							"0110000" WHEN "0011", -- symbol 3
							"0011001" WHEN "0100", -- symbol 4
							"0010010" WHEN "0101", -- symbol 5
							"0000010" WHEN "0110", -- symbol 6
							"1111000" WHEN "0111", -- symbol 7
							"0000000" WHEN "1000", -- symbol 8
							"0010000" WHEN "1001", -- symbol 9
							"0001000" WHEN "1010", -- symbol 10(A)
							"0000011" WHEN "1011", -- symbol 11(B)
							"1000110" WHEN "1100", -- symbol 12(C)
							"0100001" WHEN "1101", -- symbol 13(D)
							"0000110" WHEN "1110", -- symbol 14(E)
							"0001110" WHEN "1111", -- symbol 15(F)
							"1111111" WHEN OTHERS; -- nic nesviti	
 
END Behavioral;