martaczaska

Untitled

Apr 1st, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5.  
  6. ---- Uncomment the following library declaration if instantiating
  7. ---- any Xilinx primitives in this code.
  8. --library UNISIM;
  9. --use UNISIM.VComponents.all;
  10.  
  11. entity wyswietlacz_main is
  12. Port ( clk_i : in STD_LOGIC;
  13. rst_i : in STD_LOGIC;
  14. btn_i : in STD_LOGIC_VECTOR (3 downto 0);
  15. sw_i : in STD_LOGIC_VECTOR (7 downto 0);
  16. led7_an_o : out STD_LOGIC_VECTOR (3 downto 0);
  17. led7_seg_o : out STD_LOGIC_VECTOR (7 downto 0));
  18. end wyswietlacz_main;
  19.  
  20. architecture Behavioral of wyswietlacz_main is
  21. signal digit_current : STD_LOGIC_VECTOR (31 downto 0) := "11111111111111111111111111111111";
  22. signal button_state : STD_LOGIC_VECTOR (3 downto 0) := "0000";
  23. signal clk_1kHz : STD_LOGIC;
  24. component display
  25. port ( clk_i : in STD_LOGIC;
  26. rst_i : in STD_LOGIC;
  27. digit_i : in STD_LOGIC_VECTOR (31 downto 0);
  28. led7_an_o : out STD_LOGIC_VECTOR (3 downto 0);
  29. led7_seg_o : out STD_LOGIC_VECTOR (7 downto 0));
  30. end component;
  31. component dzielnik_main
  32. Port ( clk_i : in STD_LOGIC;
  33. rst_i : in STD_LOGIC;
  34. clk_o : out STD_LOGIC);
  35. end component;
  36. function bcd_to_7seg (bcd: STD_LOGIC_VECTOR (3 downto 0)) return STD_LOGIC_VECTOR is
  37. begin
  38. case bcd is
  39. when "0000" => return "0000001";
  40. when "0001" => return "1001111";
  41. when "0010" => return "0010010";
  42. when "0011" => return "0000110";
  43. when "0100" => return "1001100";
  44. when "0101" => return "0100100";
  45. when "0110" => return "0100000";
  46. when "0111" => return "0001111";
  47. when "1000" => return "0000000";
  48. when "1001" => return "0000100";
  49. when "1010" => return "0001000";
  50. when "1011" => return "1100000";
  51. when "1100" => return "0110001";
  52. when "1101" => return "1000010";
  53. when "1110" => return "0110000";
  54. when "1111" => return "0111000";
  55. when others => return "1111111";
  56. end case;
  57. end function bcd_to_7seg;
  58.  
  59. begin
  60. dziel: dzielnik_main port map (clk_i => clk_i,
  61. rst_i => '0',
  62. clk_o => clk_1kHz);
  63. disp: display port map (clk_i => clk_1kHz,
  64. rst_i => '0',
  65. digit_i => digit_current,
  66. led7_an_o => led7_an_o,
  67. led7_seg_o => led7_seg_o);
  68. process(clk_i)
  69. begin
  70. if (rising_edge(clk_i)) then
  71. button_state <= btn_i;
  72. digit_current(24) <= not sw_i(7);
  73. digit_current(16) <= not sw_i(6);
  74. digit_current(8) <= not sw_i(5);
  75. digit_current(0) <= not sw_i(4);
  76. if (button_state(0)='1') then digit_current (31 downto 25) <= bcd_to_7seg(sw_i(3 downto 0));
  77. elsif (button_state(1)='1') then digit_current (23 downto 17) <= bcd_to_7seg(sw_i(3 downto 0));
  78. elsif (button_state(2)='1') then digit_current (15 downto 9) <= bcd_to_7seg(sw_i(3 downto 0));
  79. elsif (button_state(3)='1') then digit_current (7 downto 1) <= bcd_to_7seg(sw_i(3 downto 0));
  80. else digit_current <= digit_current;
  81. end if;
  82. end if;
  83. end process;
  84. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment