Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.90 KB | None | 0 0
  1. library IEEE;
  2. use ieee.std_logic_1164.all;
  3. use IEEE.numeric_std.all;
  4. use ieee.std_logic_unsigned.all;
  5.  
  6. Entity SegmentDriver is
  7. port(
  8. clk_480: in std_logic;
  9. clk_counter: in std_logic;
  10. StartButton: in std_logic;
  11. reset: in std_logic;
  12. inclk : IN std_logic;
  13. cathode: out std_logic_vector (7 downto 0);
  14. anode: out std_logic_vector (3 downto 0)
  15. );
  16. End SegmentDriver;
  17.  
  18. architecture behavioral of SegmentDriver is
  19. signal PS,NS: std_logic_vector(1 downto 0):= "00";
  20. signal a,b,x,y: integer:=0;
  21. signal ss1, ss2, en : std_logic:= '0';
  22. begin
  23. process(inclk)
  24. begin
  25. if (rising_edge(inclk)) then
  26. PS <= NS;
  27. end if;
  28. end process;
  29.  
  30. adding: process (StartButton,clk_counter,PS, NS, ss1,ss2)
  31. begin
  32. if reset = '1'then
  33. a<=0;
  34. b<=0;
  35. x<=0;
  36. y<=0;
  37. else
  38. if(rising_edge(clk_counter))then
  39. if StartButton ='1' then
  40. ss1 <= '1';
  41. elsif StartButton = '0' then
  42. ss1 <= '0';
  43. end if;
  44. ss2<= ss1;
  45. if ss2 = '0' and ss1 = '1' then
  46. en <= not en;
  47. end if;
  48. case (PS) is
  49. when "11" => -- when the clock is already running
  50. if en = '1' then
  51. NS <= "11";
  52. y <= y + 1; --code to have the stopwatch actually count
  53. if y = 9 then
  54. x <= x + 1;
  55. y <= 0;
  56. if x = 9 then
  57. b <= b + 1;
  58. x <= 0;
  59. if b = 9 then
  60. a <= a + 1;
  61. b <= 0;
  62. if a = 9 then --rolls over when it gets to 99.99
  63. a <= 0;
  64. b <= 0;
  65. x <= 0;
  66. y <= 0;
  67. end if;
  68. end if;
  69. end if;
  70. end if;
  71. elsif en = '0' then
  72. NS <= "00";
  73. end if;
  74. when "00" => --when the stopwatch is stopped
  75. if en = '0' then
  76. NS <= "00";
  77. a <= a;
  78. b <= b;
  79. x <= x;
  80. y <= y;
  81. elsif en = '1' then
  82. NS <= "11";
  83. end if;
  84. when others => --should never happen
  85. NS <= "00";
  86. a <= 0;
  87. b <= 0;
  88. x <= 0;
  89. y <= 0;
  90. end case;
  91. end if;
  92. end if;
  93. end process;
  94.  
  95. led : process (clk_480) --tells leds when to turn on
  96. variable digit1, digit2: unsigned (1 downto 0):="00";
  97. begin
  98. if (rising_edge(clk_480)) then
  99. case(digit1) is
  100. when "00" => anode <= "0111";
  101. when "01" => anode <= "1011";
  102. when "10" => anode <= "1101";
  103. when "11" => anode <= "1110";
  104. when others =>
  105. end case;
  106. case (digit2) is
  107. when "00" =>
  108. case (a) is
  109. when 0 => cathode <= "00000011";
  110. when 1 => cathode <= "10011111";
  111. when 2 => cathode <= "00100101";
  112. when 3 => cathode <= "00001101";
  113. when 4 => cathode <= "10011001";
  114. when 5 => cathode <= "01001001";
  115. when 6 => cathode <= "01000001";
  116. when 7 => cathode <= "00011111";
  117. when 8 => cathode <= "00000001";
  118. when 9 => cathode <= "00011001";
  119. when others => cathode <= "00000000";
  120. end case;
  121.  
  122. when "01" =>
  123. case (b) is
  124. when 0 => cathode <= "00000010";
  125. when 1 => cathode <= "10011110";
  126. when 2 => cathode <= "00100100";
  127. when 3 => cathode <= "00001100";
  128. when 4 => cathode <= "10011000";
  129. when 5 => cathode <= "01001000";
  130. when 6 => cathode <= "01000000";
  131. when 7 => cathode <= "00011110";
  132. when 8 => cathode <= "00000000";
  133. when 9 => cathode <= "00011000";
  134. when others => cathode <= "00000000";
  135. end case;
  136.  
  137. when "10" =>
  138. case (x) is
  139. when 0 => cathode <= "00000011";
  140. when 1 => cathode <= "10011111";
  141. when 2 => cathode <= "00100101";
  142. when 3 => cathode <= "00001101";
  143. when 4 => cathode <= "10011001";
  144. when 5 => cathode <= "01001001";
  145. when 6 => cathode <= "01000001";
  146. when 7 => cathode <= "00011111";
  147. when 8 => cathode <= "00000001";
  148. when 9 => cathode <= "00011001";
  149. when others => cathode <= "00000000";
  150. end case;
  151. when "11" =>
  152. case (y) is
  153. when 0 => cathode <= "00000011";
  154. when 1 => cathode <= "10011111";
  155. when 2 => cathode <= "00100101";
  156. when 3 => cathode <= "00001101";
  157. when 4 => cathode <= "10011001";
  158. when 5 => cathode <= "01001001";
  159. when 6 => cathode <= "01000001";
  160. when 7 => cathode <= "00011111";
  161. when 8 => cathode <= "00000001";
  162. when 9 => cathode <= "00011001";
  163. when others => cathode <= "00000000";
  164. end case;
  165. when others=>
  166. -- fixes simulation bug --
  167. end case;
  168. digit1 := digit1 + 1;
  169. digit2 := digit2 + 1;
  170. end if;
  171. end process;
  172. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement