Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. --tentamenBcodeslot
  2.  
  3. library ieee;
  4. use ieee.std_logic_1164.all;
  5.  
  6. entity tentamenBcodeslot is
  7. port ( SW : in std_logic_vector(17 downto 0);
  8. KEY : in std_logic_vector(1 downto 0);
  9. LEDG : out std_logic_vector(3 downto 0);
  10. LEDR : out std_LOGIC_VECTOR(17 downto 0);
  11. HEX0 : out std_LOGIC_VECTOR(0 to 6)
  12. );
  13. end tentamenBcodeslot;
  14.  
  15. architecture arch of tentamenBcodeslot is
  16.  
  17. COMPONENT hex7seg IS
  18. PORT (
  19. hex : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
  20. display : OUT STD_LOGIC_VECTOR(0 TO 6));
  21. END COMPONENT hex7seg;
  22.  
  23. -- Build an enumerated type for the state machine
  24. type state_type is (s0, s1, s2, s3);
  25.  
  26. -- Register to hold the current state
  27. signal state : state_type;
  28. signal clk : std_logic;
  29. signal reset : std_logic;
  30. signal input : std_logic_vector(3 downto 0);
  31. signal Q : std_logic_vector(2 downto 0);
  32. signal slotopen : std_logic;
  33.  
  34. begin
  35.  
  36. clk <= not(KEY(0));
  37. reset <= not(key(1));
  38. input <= SW(3 downto 0);
  39. LEDG <= Q & slotopen;
  40. LEDR <= SW;
  41.  
  42. h0: hex7seg port map(input, HEX0);
  43.  
  44. -- Logic to advance to the next state
  45.  
  46. process (clk, reset)
  47. begin
  48. if reset = '1' then
  49. state <= s0;
  50. elsif (rising_edge(clk)) then
  51. case state is
  52. when s0=>
  53. if input = "0110" then
  54. state <= s1;
  55. else
  56. state <= s0;
  57. end if;
  58. when s1=>
  59. if input = "1010" then
  60. state <= s2;
  61. else
  62. state <= s0;
  63. end if;
  64. when s2=>
  65. if input = "0001" then
  66. state <= s3;
  67. else
  68. state <= s0;
  69. end if;
  70. when s3 =>
  71. state <= s0;
  72. end case;
  73. end if;
  74. end process;
  75.  
  76. -- Output depends solely on the current state
  77. process (state)
  78. begin
  79. case state is
  80. when s0 =>
  81. Q <= "100";
  82. slotopen <= '0';
  83. when s1 =>
  84. Q <= "110";
  85. slotopen <= '0';
  86. when s2 =>
  87. Q <= "111";
  88. slotopen <= '0';
  89. when s3 =>
  90. Q <= "000";
  91. slotopen <= '1';
  92. end case;
  93. end process;
  94.  
  95. end arch;
  96.  
  97. library ieee;
  98. use ieee.std_logic_1164.all;
  99.  
  100. ENTITY hex7seg IS
  101. PORT (
  102. hex : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
  103. display : OUT STD_LOGIC_VECTOR(0 TO 6));
  104. END hex7seg;
  105.  
  106. ARCHITECTURE Behavior OF hex7seg IS
  107. BEGIN
  108. --
  109. -- 0
  110. -- ---
  111. -- | |
  112. -- 5| |1
  113. -- | 6 |
  114. -- ---
  115. -- | |
  116. -- 4| |2
  117. -- | |
  118. -- ---
  119. -- 3
  120. --
  121. PROCESS ( hex)
  122. BEGIN
  123. CASE hex IS
  124. WHEN "0000" => display <= "0000001";
  125. WHEN "0001" => display <= "1001111";
  126. WHEN "0010" => display <= "0010010";
  127. WHEN "0011" => display <= "0000110";
  128. WHEN "0100" => display <= "1001100";
  129. WHEN "0101" => display <= "0100100";
  130. WHEN "0110" => display <= "0100000";
  131. WHEN "0111" => display <= "0001111";
  132. WHEN "1000" => display <= "0000000";
  133. WHEN "1001" => display <= "0000100";
  134. WHEN "1010" => display <= "0001000";
  135. WHEN "1011" => display <= "1100000";
  136. WHEN "1100" => display <= "0110001";
  137. WHEN "1101" => display <= "1000010";
  138. WHEN "1110" => display <= "0110000";
  139. WHEN "1111" => display <= "0111000";
  140. WHEN OTHERS => display <= "1111111"; -- empty
  141. END CASE;
  142. END PROCESS;
  143.  
  144. END behavior;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement