akmalgtg

Untitled

Nov 29th, 2021
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.92 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    22:19:51 11/28/2021
  6. -- Design Name:
  7. -- Module Name:    top - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22.  
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. --use IEEE.NUMERIC_STD.ALL;
  26.  
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31.  
  32. entity top is
  33.     Port ( pb1 : in  STD_LOGIC;
  34.            pb2 : in  STD_LOGIC;
  35.            switch : in  STD_LOGIC_VECTOR (3 downto 0);
  36.            led : out  STD_LOGIC_VECTOR (4 downto 0);
  37.            mode : out  STD_LOGIC_VECTOR (2 downto 0));
  38. end top;
  39.  
  40. architecture Behavioral of top is
  41.     type eg_state_type is (s0, s1, s2);
  42.     signal state_reg, state_next: eg_state_type;
  43.     signal ascii: STD_LOGIC_VECTOR (7 downto 0);
  44. begin
  45.  
  46.     -- state register
  47.     process(pb1, pb2,state_reg)
  48.     begin
  49.         if(pb2 = '1') then
  50.             state_reg <= s0;
  51.         elsif(pb1'event and pb1 = '1') then
  52.             case state_reg is
  53.                 when s0 =>
  54.                     ascii(7) <= switch(3);
  55.                     ascii(6) <= switch(2);
  56.                     ascii(5) <= switch(1);
  57.                     ascii(4) <= switch(0);
  58.                 when s1 =>
  59.                     ascii(3) <= switch(3);
  60.                     ascii(2) <= switch(2);
  61.                     ascii(1) <= switch(1);
  62.                     ascii(0) <= switch(0);
  63.                 when s2 =>
  64.                     ascii <= "00000000";
  65.             end case;
  66.             state_reg <= state_next;
  67.         end if;
  68.     end process;
  69.    
  70.     -- next-state logic
  71.     process(state_reg)
  72.     begin
  73.         case state_reg is
  74.             when s0 =>
  75.                 state_next <= s1;
  76.             when s1 =>
  77.                 state_next <= s2;
  78.             when s2 =>
  79.                 state_next <= s0;
  80.         end case;
  81.     end process;
  82.    
  83.     -- output logic
  84.         process(state_reg)
  85.         begin
  86.             case state_reg is
  87.                 when s0 =>
  88.                     led <= "00000";
  89.                     mode <= "111";
  90.                 when s1 =>
  91.                     led <= "00000";
  92.                     mode <= "111";
  93.                 when s2 =>
  94.                     case ascii is
  95.                         -- ANGKA
  96.                         when x"31" => -- 1
  97.                             led <= "10000";
  98.                             mode <= "101";
  99.                         when x"32" => -- 2
  100.                             led <= "11000";
  101.                             mode <= "101";
  102.                         when x"33" => -- 3
  103.                             led <= "11100";
  104.                             mode <= "101";
  105.                         when x"34" => -- 4
  106.                             led <= "11110";
  107.                             mode <= "101";
  108.                         when x"35" => -- 5
  109.                             led <= "11111";
  110.                             mode <= "101";
  111.                         when x"36" => -- 6
  112.                             led <= "01111";
  113.                             mode <= "101";
  114.                         when x"37" => -- 7
  115.                             led <= "00111";
  116.                             mode <= "101";
  117.                         when x"38" => -- 8
  118.                             led <= "00011";
  119.                             mode <= "101";
  120.                         when x"39" => -- 9
  121.                             led <= "00001";
  122.                             mode <= "101";
  123.                         when x"30" => -- 0
  124.                             led <= "00000";
  125.                             mode <= "101";
  126.                         -- HURUF
  127.                         when x"41" => -- A
  128.                             led <= "00010";
  129.                             mode <= "010";
  130.                         when x"42" => -- B
  131.                             led <= "00111";
  132.                             mode <= "100";
  133.                         when x"43" => -- C
  134.                             led <= "00101";
  135.                             mode <= "100";
  136.                         when x"44" => -- D
  137.                             led <= "00011";
  138.                             mode <= "011";
  139.                         when x"45" => -- E
  140.                             led <= "00001";
  141.                             mode <= "001";
  142.                         when x"46" => -- F
  143.                             led <= "01101";
  144.                             mode <= "100";
  145.                         when x"47" => -- G
  146.                             led <= "00001";
  147.                             mode <= "011";
  148.                         when x"48" => -- H
  149.                             led <= "01111";
  150.                             mode <= "100";
  151.                         when x"49" => -- I
  152.                             led <= "00011";
  153.                             mode <= "010";
  154.                         when x"4A" => -- J
  155.                             led <= "01000";
  156.                             mode <= "100";
  157.                         when x"4B" => -- K
  158.                             led <= "00010";
  159.                             mode <= "011";
  160.                         when x"4C" => -- L
  161.                             led <= "01011";
  162.                             mode <= "100";
  163.                         when x"4D" => -- M
  164.                             led <= "00000";
  165.                             mode <= "010";
  166.                         when x"4E" => -- N
  167.                             led <= "00001";
  168.                             mode <= "010";
  169.                         when x"4F" => -- O
  170.                             led <= "00000";
  171.                             mode <= "011";
  172.                         when x"50" => -- P
  173.                             led <= "01001";
  174.                             mode <= "100";
  175.                         when x"51" => -- Q
  176.                             led <= "00010";
  177.                             mode <= "100";
  178.                         when x"52" => -- R
  179.                             led <= "00101";
  180.                             mode <= "011";
  181.                         when x"53" => -- S
  182.                             led <= "00111";
  183.                             mode <= "011";
  184.                         when x"54" => -- T
  185.                             led <= "00000";
  186.                             mode <= "001";
  187.                         when x"55" => -- U
  188.                             led <= "00110";
  189.                             mode <= "011";
  190.                         when x"56" => -- V
  191.                             led <= "01110";
  192.                             mode <= "100";
  193.                         when x"57" => -- W
  194.                             led <= "00100";
  195.                             mode <= "011";
  196.                         when x"58" => -- X
  197.                             led <= "00110";
  198.                             mode <= "100";
  199.                         when x"59" => -- Y
  200.                             led <= "00100";
  201.                             mode <= "100";
  202.                         when x"5A" => -- Z
  203.                             led <= "00011";
  204.                             mode <= "100";
  205.                         when others =>
  206.                             led <= "00000";
  207.                             mode <= "000";
  208.                     end case;
  209.             end case;
  210.         end process;
  211.  
  212. end Behavioral;
Add Comment
Please, Sign In to add comment