myfirst_niosii.vhd 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. entity myfirst_niosii is port (
  6. clk: in std_logic;
  7. rst: in std_logic;
  8. pio_led: out std_logic_vector(31 downto 0);
  9. toggle_button: in std_logic;
  10. toggle_led: out std_logic
  11. );
  12. end myfirst_niosii;
  13. architecture behav of myfirst_niosii is
  14. component nios2_uc is
  15. port (
  16. clk_clk : in std_logic := 'X'; -- clk
  17. pio_led_ext_conn_export : out std_logic_vector(31 downto 0); -- export
  18. reset_reset_n : in std_logic := 'X' -- reset_n
  19. );
  20. end component nios2_uc;
  21. signal toggle_led_s: std_logic := '0';
  22. signal state: std_logic := '0';
  23. signal counter: integer range 0 to 2**15-1 := 0;
  24. begin
  25. u0 : component nios2_uc
  26. port map (
  27. clk_clk => clk, -- clk.clk
  28. pio_led_ext_conn_export => pio_led, -- pio_led_ext_conn.export
  29. reset_reset_n => rst -- reset.reset_n
  30. );
  31. toggle: process(clk, rst)
  32. begin
  33. if rst = '0' then
  34. counter <= 0;
  35. state <= '0';
  36. elsif rising_edge(clk) then
  37. if counter = 2**15-1 then
  38. counter <= 0;
  39. if toggle_button = not state then
  40. state <= toggle_button;
  41. if toggle_button = '1' then
  42. toggle_led_s <= not toggle_led_s;
  43. end if;
  44. end if;
  45. else
  46. counter <= counter + 1;
  47. end if;
  48. end if;
  49. end process;
  50. toggle_led <= toggle_led_s;
  51. end behav;