Advertisement
PauloTiming

circuitosdigitais_exe4

Jun 3rd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity Topo is port (
  5. SW: in std_logic_vector(9 downto 0);
  6. KEY: in std_logic_vector(3 downto 0);
  7. LEDR: out std_logic_vector(7 downto 0);
  8. HEX0: out std_logic_vector(6 downto 0);
  9. HEX1: out std_logic_vector(6 downto 0);
  10. CLOCK_50: in std_logic
  11. );
  12. end Topo;
  13.  
  14. architecture topo_beh of Topo is
  15. signal BTN: std_logic_vector(3 downto 0);
  16. signal LED: std_logic_vector(7 downto 0);
  17.  
  18. component ButtonSync is
  19. port
  20. (
  21. KEY0, KEY1, KEY2, KEY3, CLK: in std_logic;
  22. BTN0, BTN1, BTN2, BTN3: out std_logic
  23. );
  24. end component;
  25.  
  26. component decod is
  27. port (H: in std_logic_vector(3 downto 0);
  28. C: out std_logic_vector(6 downto 0)
  29. );
  30. end component;
  31.  
  32. component Multimodo is port (
  33. SW: in std_logic_vector(7 downto 0);
  34. muxInput: in std_logic_vector(1 downto 0);
  35. BTN0: in std_logic; --Reset
  36. BTN1: in std_logic; --LOad
  37. clock: in std_logic;
  38. LED: out std_logic_vector(7 downto 0)
  39. );
  40. end component;
  41.  
  42. Begin
  43. C0: ButtonSync port map (KEY(0),KEY(1),KEY(2), KEY(3), CLOCK_50, BTN(0), BTN(1), BTN(2), BTN(3));
  44. M0: Multimodo port map (SW(7 downto 0), SW(9 downto 8), BTN(0) , BTN(1), CLOCK_50, LED);
  45. DC1: decod port map (LED(3 downto 0),HEX0);
  46. DC2: decod port map (LED(7 downto 4),HEX1);
  47. LEDR <= LED;
  48. end topo_beh;
  49.  
  50. ---------------------------------------------------
  51. library ieee;
  52. use ieee.std_logic_1164.all;
  53. use IEEE.std_logic_arith.all;
  54. use IEEE.std_logic_unsigned.all;
  55.  
  56. entity Multimodo is port (
  57. SW: in std_logic_vector(7 downto 0);
  58. muxInput: in std_logic_vector(1 downto 0);
  59. BTN0: in std_logic; --Reset
  60. BTN1: in std_logic; --LOad
  61. clock: in std_logic;
  62. LED: out std_logic_vector(7 downto 0)
  63. );
  64. end Multimodo;
  65.  
  66. architecture arqdtp of Multimodo is
  67. signal tot: std_logic_vector(7 downto 0);
  68. signal muxValue: std_logic_vector(7 downto 0);
  69. signal dir: std_logic_vector(7 downto 0);
  70. signal esq: std_logic_vector(7 downto 0);
  71. begin
  72.  
  73. dir <= '0'&tot(7 downto 1);
  74. esq <= tot(6 downto 0)&'0';
  75.  
  76. muxValue <= tot + SW when muxInput = "00" else
  77. SW when muxInput = "01" else
  78. dir when muxInput = "10" else
  79. esq when muxInput = "11";
  80.  
  81.  
  82. -- Registrador e Somador:
  83. process(clock,BTN0,BTN1)
  84. begin
  85. if (BTN0 = '0') then
  86. tot <= "00000000";
  87. elsif (clock'event AND clock = '1') then
  88. if (BTN1 = '0') then
  89. tot <= muxValue;
  90. end if;
  91. end if;
  92. end process;
  93. LED <= tot;
  94. end arqdtp;
  95.  
  96. ------------------------------------------------------------
  97. -- Button Press Synchronizer para keys que são ativas baixas (ou seja, quando pressionadas vao para nivel baixo)
  98.  
  99. library ieee;
  100. use ieee.std_logic_1164.all;
  101.  
  102. entity ButtonSync is
  103. port
  104. (
  105. KEY0, KEY1, KEY2, KEY3, CLK: in std_logic;
  106. BTN0, BTN1, BTN2, BTN3: out std_logic
  107. );
  108. end ButtonSync;
  109.  
  110.  
  111. architecture ButtonSyncImpl of ButtonSync is
  112. type STATES is (EsperaApertar, SaidaAtiva, EsperaSoltar);
  113. signal btn0state, btn1state, btn2state, btn3state : STATES := EsperaApertar;
  114. signal btn0next, btn1next, btn2next, btn3next : STATES := EsperaApertar;
  115. begin
  116.  
  117. process (clk)
  118. begin
  119. if clk'event and clk = '1' then -- Resposta na transicao positiva do clock
  120. btn0state <= btn0next;
  121. btn1state <= btn1next;
  122. btn2state <= btn2next;
  123. btn3state <= btn3next;
  124. end if;
  125. end process;
  126.  
  127. process (key0,btn0state)
  128. begin
  129. case btn0state is
  130. when EsperaApertar =>
  131. if key0 = '0' then btn0next <= SaidaAtiva; else btn0next <= EsperaApertar; end if;
  132. btn0 <= '1';
  133. when SaidaAtiva =>
  134. if key0 = '0' then btn0next <= EsperaSoltar; else btn0next <= EsperaApertar; end if;
  135. btn0 <= '0';
  136. when EsperaSoltar =>
  137. if key0 = '0' then btn0next <= EsperaSoltar; else btn0next <= EsperaApertar; end if;
  138. btn0 <= '1';
  139. end case;
  140. end process;
  141.  
  142. process (key1,btn1state)
  143. begin
  144. case btn1state is
  145. when EsperaApertar =>
  146. if key1 = '0' then btn1next <= SaidaAtiva; else btn1next <= EsperaApertar; end if;
  147. btn1 <= '1';
  148. when SaidaAtiva =>
  149. if key1 = '0' then btn1next <= EsperaSoltar; else btn1next <= EsperaApertar; end if;
  150. btn1 <= '0';
  151. when EsperaSoltar =>
  152. if key1 = '0' then btn1next <= EsperaSoltar; else btn1next <= EsperaApertar; end if;
  153. btn1 <= '1';
  154. end case;
  155. end process;
  156.  
  157. process (key2,btn2state)
  158. begin
  159. case btn2state is
  160. when EsperaApertar =>
  161. if key2 = '0' then btn2next <= SaidaAtiva; else btn2next <= EsperaApertar; end if;
  162. btn2 <= '1';
  163. when SaidaAtiva =>
  164. if key2 = '0' then btn2next <= EsperaSoltar; else btn2next <= EsperaApertar; end if;
  165. btn2 <= '0';
  166. when EsperaSoltar =>
  167. if key2 = '0' then btn2next <= EsperaSoltar; else btn2next <= EsperaApertar; end if;
  168. btn2 <= '1';
  169. end case;
  170. end process;
  171.  
  172. process (key3,btn3state)
  173. begin
  174. case btn3state is
  175. when EsperaApertar =>
  176. if key3 = '0' then btn3next <= SaidaAtiva; else btn3next <= EsperaApertar; end if;
  177. btn3 <= '1';
  178. when SaidaAtiva =>
  179. if key3 = '0' then btn3next <= EsperaSoltar; else btn3next <= EsperaApertar; end if;
  180. btn3 <= '0';
  181. when EsperaSoltar =>
  182. if key3 = '0' then btn3next <= EsperaSoltar; else btn3next <= EsperaApertar; end if;
  183. btn3 <= '1';
  184. end case;
  185. end process;
  186.  
  187. end ButtonSyncImpl;
  188. ------------------------------------------------------------
  189. library IEEE;
  190. use IEEE.Std_Logic_1164.all;
  191.  
  192. entity decod is
  193. port (H: in std_logic_vector(3 downto 0);
  194. C: out std_logic_vector(6 downto 0)
  195. );
  196. end entity;
  197.  
  198. architecture decoder of decod is
  199. begin
  200. C <= "1000000" when H = "0000" else
  201. "1111001" when H = "0001" else
  202. "0100100" when H = "0010" else
  203. "0110000" when H = "0011" else
  204. "0011001" when H = "0100" else
  205. "0010010" when H = "0101" else
  206. "0000010" when H = "0110" else
  207. "1111000" when H = "0111" else
  208. "0000000" when H = "1000" else
  209. "0011000" when H = "1001" else
  210. "0001000" when H = "1010" else
  211. "0000011" when H = "1011" else
  212. "1000110" when H = "1100" else
  213. "0100001" when H = "1101" else
  214. "0000110" when H = "1110" else
  215. "0001110";
  216.  
  217. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement