seven_seg.vhd 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 06/07/2023 11:23:28 PM
  6. -- Design Name:
  7. -- Module Name: seven_seg - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool Versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. --use IEEE.NUMERIC_STD.ALL;
  26. -- Uncomment the following library declaration if instantiating
  27. -- any Xilinx leaf cells in this code.
  28. --library UNISIM;
  29. --use UNISIM.VComponents.all;
  30. entity seven_seg is
  31. Port ( clk : in STD_LOGIC;
  32. data : in STD_LOGIC_VECTOR (15 downto 0);
  33. seg : out STD_LOGIC_VECTOR (7 downto 0);
  34. ssel : out STD_LOGIC_VECTOR (3 downto 0));
  35. end seven_seg;
  36. architecture Behavioral of seven_seg is
  37. signal count : std_logic_vector (12 downto 0) := '0'&x"000";
  38. signal digit : std_logic_vector (3 downto 0);
  39. begin
  40. process(clk,count,data)
  41. begin
  42. if(rising_edge(clk))
  43. then
  44. count <= count + 1;
  45. end if;
  46. case count(12 downto 10) is
  47. when "000" =>
  48. ssel <= "1110";
  49. digit <= data(3 downto 0);
  50. when "010" =>
  51. ssel <= "1101";
  52. digit <= data(7 downto 4);
  53. when "100" =>
  54. ssel <= "1011";
  55. digit <= data(11 downto 8);
  56. when "110" =>
  57. ssel <= "0111";
  58. digit <= data(15 downto 12);
  59. when others =>
  60. ssel <= (others => '1');
  61. digit <= x"8";
  62. end case;
  63. end process;
  64. seg <= "10000001" when digit = x"0" else
  65. "11111001" when digit = x"1" else
  66. "10100100" when digit = x"2" else
  67. "10110000" when digit = x"3" else
  68. "10011001" when digit = x"4" else
  69. "10010010" when digit = x"5" else
  70. "10000011" when digit = x"6" else
  71. "11111000" when digit = x"7" else
  72. "10000000" when digit = x"8" else
  73. "10011000" when digit = x"9" else
  74. "10001000" when digit = x"A" else
  75. "10000011" when digit = x"B" else
  76. "11000110" when digit = x"C" else
  77. "10100001" when digit = x"D" else
  78. "10000110" when digit = x"E" else
  79. "10001110" when digit = x"F" else
  80. "01111111";
  81. end Behavioral;