Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 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. entity projekt7 is
  7. port (
  8. start_stop_button_i: in STD_LOGIC;
  9. clk_i: in STD_LOGIC;
  10. rst_i: in STD_LOGIC;
  11. led7_an_o: out STD_LOGIC_VECTOR (3 downto 0);
  12. led7_seg_o: out STD_LOGIC_VECTOR (7 downto 0)
  13. );
  14.  
  15. end projekt7;
  16.  
  17. architecture behavioral of projekt7 is
  18.  
  19. component projekt6noinput
  20. port (
  21. clk_i: in std_logic;
  22. rst_i: in std_logic;
  23. led7_an_o: out std_logic_vector(3 downto 0) := "0000";
  24. digit_i: in std_logic_vector(31 downto 0);
  25. led7_seg_o: out std_logic_vector(7 downto 0)
  26. );
  27. end component;
  28.  
  29. component projekt5noreset
  30. port (
  31. clk_i : in std_logic;
  32. clk_o : out std_logic
  33. );
  34. end component;
  35.  
  36. signal timer_start: std_logic := '0';
  37. signal timer_stop: std_logic := '0';
  38. signal clk_o: std_logic;
  39. signal digit_i: std_logic_vector (31 downto 0) := "00000011000000100000001100000011";
  40. type time_array is array (0 to 4) of integer range 0 to 10;
  41. signal cur_time: time_array := (others => 0);
  42. --signal vibs: integer range 0 to 2;
  43.  
  44. function seg(data: integer range 0 to 9) return std_logic_vector is
  45. begin
  46. case data is
  47. when 0 => return ("0000001"); -- 0
  48. when 1 => return ("1001111"); -- 1
  49. when 2 => return ("0010010"); -- 2
  50. when 3 => return ("0000110"); -- 3
  51. when 4 => return ("1001100"); -- 4
  52. when 5 => return ("0100100"); -- 5
  53. when 6 => return ("0100000"); -- 6
  54. when 7 => return ("0001111"); -- 7
  55. when 8 => return ("0000000"); -- 8
  56. when 9 => return ("0000100"); -- 9
  57. when others => return ("0000001"); -- 0
  58. end case;
  59. end function seg;
  60.  
  61. function seg_time(data: time_array) return std_logic_vector is
  62. variable temp : std_logic_vector(31 downto 0);
  63. begin
  64. if (data(4) = 6) then
  65. temp := "11111101111111001111110111111101";
  66. else
  67. temp(0) := '1';
  68. temp(8) := '1';
  69. temp(16) := '0';
  70. temp(24) := '1';
  71. temp(7 downto 1) := seg(data(1));
  72. temp(15 downto 9) := seg(data(2));
  73. temp(23 downto 17) := seg(data(3));
  74. temp(31 downto 25) := seg(data(4));
  75. end if;
  76. return temp;
  77. end function seg_time;
  78.  
  79. begin
  80.  
  81. projekt5: projekt5noreset port map (clk_i => clk_i, clk_o => clk_o);
  82. projekt6: projekt6noinput port map (clk_i => clk_i, rst_i => rst_i, led7_an_o => led7_an_o, led7_seg_o => led7_seg_o, digit_i => digit_i);
  83.  
  84. --process(clk_o)
  85. -- variable counter: integer := 0;
  86. -- begin
  87. -- if(rising_edge(clk_o)) then
  88. -- if(start_stop_button_i = '1') then
  89. -- vibs <= 0;
  90. -- counter := counter + 1;
  91. -- else
  92. -- if(counter > 50) then
  93. -- if(vibs = 2) then
  94. -- vibs <= 0;
  95. -- else
  96. -- vibs <= vibs + 1;
  97. -- end if;
  98. -- end if;
  99. -- counter := 0;
  100. -- end if;
  101. -- end if;
  102. --end process;
  103.  
  104. process (clk_o, rst_i)
  105. begin
  106.  
  107. if (rst_i = '1') then
  108. cur_time(0) <= 0;
  109. cur_time(1) <= 0;
  110. cur_time(2) <= 0;
  111. cur_time(3) <= 0;
  112. cur_time(4) <= 0;
  113. elsif (rising_edge(clk_o)) then
  114. if (start_stop_button_i = '1') then
  115. if (timer_start = '0' and timer_stop = '0') then -- and vibs = 1
  116. timer_start <= '1';
  117. elsif (timer_start = '1' and timer_stop = '0') then
  118. timer_stop <= '1';
  119. elsif (timer_start = '1' and timer_stop = '1') then
  120. timer_start <= '0';
  121. timer_stop <= '0';
  122. end if;
  123. end if;
  124. if (timer_start = '0' and timer_stop = '0') then
  125. cur_time(0) <= 0;
  126. cur_time(1) <= 0;
  127. cur_time(2) <= 0;
  128. cur_time(3) <= 0;
  129. cur_time(4) <= 0;
  130. end if;
  131. if (timer_start = '1' and timer_stop = '0') then
  132. cur_time(0) <= cur_time(0) + 1;
  133.  
  134. if (cur_time(0) = 9) then
  135. cur_time(0) <= 0;
  136. cur_time(1) <= cur_time(1) + 1;
  137. end if;
  138.  
  139. if (cur_time(1) = 10) then
  140. cur_time(1) <= 0;
  141. cur_time(2) <= cur_time(2) + 1;
  142. end if;
  143.  
  144. if (cur_time(2) = 10) then
  145. cur_time(2) <= 0;
  146. cur_time(3) <= cur_time(3) + 1;
  147. end if;
  148.  
  149. if (cur_time(3) = 10) then
  150. cur_time(3) <= 0;
  151. cur_time(4) <= cur_time(4) + 1;
  152. end if;
  153.  
  154. if (cur_time(4) = 6) then
  155. timer_stop <= '1';
  156. end if;
  157. end if;
  158. end if;
  159. end process;
  160. digit_i <= seg_time(cur_time);
  161. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement