Advertisement
PauloTiming

exercicio_3

Sep 30th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity exercicio3 is
  5. port (LEDR: out std_logic_vector(3 downto 0);
  6. KEY: in std_logic_vector(1 downto 0);
  7. HEX0: out std_logic_vector(6 downto 0)
  8. );
  9. end exercicio3;
  10.  
  11. architecture topo_beh of exercicio3 is
  12. signal Qn: std_logic_vector(3 downto 0);
  13. signal Y: std_logic_vector(3 downto 0);
  14.  
  15. -----------------componentes------------
  16. component logica is
  17. port( a: in std_logic_vector(3 downto 0);
  18. b: out std_logic_vector(3 downto 0)
  19. );
  20. end component;
  21.  
  22. component decod7seg is
  23. port (C: in std_logic_vector(3 downto 0);
  24. F: out std_logic_vector(6 downto 0)
  25. );
  26. end component;
  27.  
  28. component D_4FF is --reg
  29. port (CLK: in std_logic;
  30. RST: in std_logic;
  31. EN: in std_logic;
  32. D: in std_logic_vector(3 downto 0);
  33. Q: out std_logic_vector(3 downto 0)
  34. );
  35. end component;
  36. ----------------------------------------
  37. Begin
  38. LOG: logica port map( Y(3 downto 0), Qn(3 downto 0) );
  39. REG: D_4FF port map( KEY(1), KEY(0), '0', Qn(3 downto 0), Y(3 downto 0));
  40. DEC0: decod7seg port map( Y(3 downto 0), HEX0(6 downto 0) );
  41. end topo_beh;
  42. -- 0 1 3 2 E 6 7 F
  43.  
  44.  
  45. ------------------------------------------------------- flipflop
  46. library ieee;
  47. use ieee.std_logic_1164.all;
  48. entity D_4FF is
  49. port (
  50. CLK: in std_logic;
  51. RST: in std_logic;
  52. EN: in std_logic;
  53. D: in std_logic_vector(3 downto 0);
  54. Q: out std_logic_vector(3 downto 0)
  55. );
  56. end D_4FF;
  57.  
  58. architecture behv of D_4FF is
  59. begin
  60. process(CLK, D, RST, EN)
  61. begin
  62. if RST = '0' then
  63. Q <= "0000";
  64. elsif (CLK'event and CLK = '1') then
  65. if EN = '0' then
  66. Q <= D;
  67. end if;
  68. end if;
  69. end process;
  70. end behv;
  71.  
  72. -----------------------------------------------
  73. library ieee;
  74. use ieee.std_logic_1164.all;
  75.  
  76. entity logica is
  77. port( a: in std_logic_vector(3 downto 0);
  78. b: out std_logic_vector(3 downto 0)
  79. );
  80. end logica;
  81.  
  82. architecture bhv of logica is
  83. begin
  84. b(3)<= ( not(a(1)) and not(a(0)) )or( a(1) and a(0) and a(2) and not(a(3)) );
  85. b(2)<= (not(a(3)) and a(0) )or( a(3) and not(a(2)));
  86. b(1)<= not(a(1)) or not(a(3));
  87. b(0)<= (not(a(2)) and a(1) )or( a(1) and a(0) and not(a(3)));
  88. end bhv;
  89. ---------------------------------------------------------
  90. library IEEE;
  91. use IEEE.Std_Logic_1164.all;
  92.  
  93. entity decod7seg is
  94. port (C: in std_logic_vector(3 downto 0);
  95. F: out std_logic_vector(6 downto 0)
  96. );
  97. end decod7seg;
  98.  
  99. architecture decod of decod7seg is
  100. begin
  101. F <= "1000000" when C = "0000" else --0
  102. "1111001" when C = "0001" else --1
  103. "0000110" when C = "0010" else --2
  104. "0000010" when C = "0011" else --3
  105. "0011001" when C = "0100" else --4
  106. "0110000" when C = "0101" else --5
  107. "0100100" when C = "0110" else --6
  108. "1111000" when C = "0111" else --7
  109. "0000000" when C = "1000" else --8
  110. "0011000" when C = "1001" else --9
  111. "1111001" when C = "1010" else --A
  112. "0000011" when C = "1011" else --B
  113. "1000110" when C = "1100" else --C
  114. "0100001" when C = "1101" else --D
  115. "0000110" when C = "1110" else --E
  116. "0001110" when C = "1111" else --F
  117. "1111111";
  118. end decod;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement