Advertisement
PauloTiming

lab 6

Oct 7th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. entity Topo is
  4. port ( LEDR: out std_logic_vector(3 downto 0);
  5. CLOCK_50: in std_logic;
  6. KEY: in std_logic_vector(2 downto 0);
  7. HEX0: out std_logic_vector(6 downto 0)
  8. );
  9. end Topo;
  10. architecture topo_beh of Topo is
  11. component FSM_Conta
  12. port (
  13. clock: in std_logic;
  14. x: in std_logic;
  15. y: out std_logic_vector(3 downto 0);
  16. rst: in std_logic
  17. );
  18. end component;
  19.  
  20. component decod7seg
  21. port(
  22. C: in std_logic_vector(3 downto 0);
  23. G: out std_logic_vector(6 downto 0)
  24. );
  25. end component;
  26.  
  27. component div_freq
  28. port(
  29. reset: in std_logic;
  30. clock: in std_logic;
  31. C1Hz: out std_logic
  32. );
  33. end component;
  34.  
  35. signal F: std_logic;
  36. signal Y: std_logic_vector(3 downto 0);
  37.  
  38. Begin
  39. L0: div_freq port map (KEY(), CLOCK_50, F);
  40. L1: FSM_Conta port map (F, KEY(1), Y, KEY(0));
  41. L2: decod7seg port map (Y, HEX0);
  42. LEDR <= Y;
  43. end topo_beh;
  44.  
  45. --------------------------------------------------------------------------fsm_conta
  46.  
  47. library ieee;
  48. use ieee.std_logic_1164.all;
  49. entity FSM_Conta is port(
  50. clock: in std_logic;
  51. x: in std_logic;
  52. y: out std_logic_vector(3 downto 0);
  53. rst: in std_logic
  54. );
  55.  
  56. end FSM_Conta;
  57.  
  58. architecture bhv of FSM_Conta is
  59. type STATES is (E0, E1, E2, E3, E4);
  60. signal EA, PE: STATES;
  61. signal contagem: std_logic_vector(3 downto 0);
  62. begin
  63. P1: process(clock, rst)
  64. begin
  65. if rst= '0' then
  66. EA <= E0;
  67. elsif clock'event and clock= '0' then
  68. EA <= PE;
  69. end if;
  70. end process;
  71. P2: process(EA)
  72. begin
  73. case EA is
  74. when E0 =>
  75. contagem <= "0001";
  76. if x='1' then PE <= E1; else PE <= E0; end if;
  77.  
  78. when E1 =>
  79. contagem <= "0010";
  80. if x='1' then PE <= E2; else PE <= E1; end if;
  81. when E2 =>
  82. contagem <= "0011";
  83. if x='1' then PE <= E3; else PE <= E2; end if;
  84. when E3 =>
  85. contagem <= "0100";
  86. if x='1' then PE <= E4; else PE <= E3; end if;
  87. when E4 =>
  88. contagem <= "0101";
  89. if x='1' then PE <= E0; else PE <= E4; end if;
  90. end case;
  91.  
  92. end process;
  93.  
  94. y <= contagem;
  95. end bhv;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement