Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------------
- -- Company:
- -- Engineer:
- --
- -- Create Date: 22:19:51 11/28/2021
- -- Design Name:
- -- Module Name: top - Behavioral
- -- Project Name:
- -- Target Devices:
- -- Tool versions:
- -- Description:
- --
- -- Dependencies:
- --
- -- Revision:
- -- Revision 0.01 - File Created
- -- Additional Comments:
- --
- ----------------------------------------------------------------------------------
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- -- Uncomment the following library declaration if using
- -- arithmetic functions with Signed or Unsigned values
- --use IEEE.NUMERIC_STD.ALL;
- -- Uncomment the following library declaration if instantiating
- -- any Xilinx primitives in this code.
- --library UNISIM;
- --use UNISIM.VComponents.all;
- entity top is
- Port ( pb1 : in STD_LOGIC;
- pb2 : in STD_LOGIC;
- switch : in STD_LOGIC_VECTOR (3 downto 0);
- led : out STD_LOGIC_VECTOR (4 downto 0);
- mode : out STD_LOGIC_VECTOR (2 downto 0));
- end top;
- architecture Behavioral of top is
- type eg_state_type is (s0, s1, s2);
- signal state_reg, state_next: eg_state_type;
- signal ascii: STD_LOGIC_VECTOR (7 downto 0);
- begin
- -- state register
- process(pb1, pb2,state_reg)
- begin
- if(pb2 = '1') then
- state_reg <= s0;
- elsif(pb1'event and pb1 = '1') then
- case state_reg is
- when s0 =>
- ascii(7) <= switch(3);
- ascii(6) <= switch(2);
- ascii(5) <= switch(1);
- ascii(4) <= switch(0);
- when s1 =>
- ascii(3) <= switch(3);
- ascii(2) <= switch(2);
- ascii(1) <= switch(1);
- ascii(0) <= switch(0);
- when s2 =>
- ascii <= "00000000";
- end case;
- state_reg <= state_next;
- end if;
- end process;
- -- next-state logic
- process(state_reg)
- begin
- case state_reg is
- when s0 =>
- state_next <= s1;
- when s1 =>
- state_next <= s2;
- when s2 =>
- state_next <= s0;
- end case;
- end process;
- -- output logic
- process(state_reg)
- begin
- case state_reg is
- when s0 =>
- led <= "00000";
- mode <= "111";
- when s1 =>
- led <= "00000";
- mode <= "111";
- when s2 =>
- case ascii is
- -- ANGKA
- when x"31" => -- 1
- led <= "10000";
- mode <= "101";
- when x"32" => -- 2
- led <= "11000";
- mode <= "101";
- when x"33" => -- 3
- led <= "11100";
- mode <= "101";
- when x"34" => -- 4
- led <= "11110";
- mode <= "101";
- when x"35" => -- 5
- led <= "11111";
- mode <= "101";
- when x"36" => -- 6
- led <= "01111";
- mode <= "101";
- when x"37" => -- 7
- led <= "00111";
- mode <= "101";
- when x"38" => -- 8
- led <= "00011";
- mode <= "101";
- when x"39" => -- 9
- led <= "00001";
- mode <= "101";
- when x"30" => -- 0
- led <= "00000";
- mode <= "101";
- -- HURUF
- when x"41" => -- A
- led <= "00010";
- mode <= "010";
- when x"42" => -- B
- led <= "00111";
- mode <= "100";
- when x"43" => -- C
- led <= "00101";
- mode <= "100";
- when x"44" => -- D
- led <= "00011";
- mode <= "011";
- when x"45" => -- E
- led <= "00001";
- mode <= "001";
- when x"46" => -- F
- led <= "01101";
- mode <= "100";
- when x"47" => -- G
- led <= "00001";
- mode <= "011";
- when x"48" => -- H
- led <= "01111";
- mode <= "100";
- when x"49" => -- I
- led <= "00011";
- mode <= "010";
- when x"4A" => -- J
- led <= "01000";
- mode <= "100";
- when x"4B" => -- K
- led <= "00010";
- mode <= "011";
- when x"4C" => -- L
- led <= "01011";
- mode <= "100";
- when x"4D" => -- M
- led <= "00000";
- mode <= "010";
- when x"4E" => -- N
- led <= "00001";
- mode <= "010";
- when x"4F" => -- O
- led <= "00000";
- mode <= "011";
- when x"50" => -- P
- led <= "01001";
- mode <= "100";
- when x"51" => -- Q
- led <= "00010";
- mode <= "100";
- when x"52" => -- R
- led <= "00101";
- mode <= "011";
- when x"53" => -- S
- led <= "00111";
- mode <= "011";
- when x"54" => -- T
- led <= "00000";
- mode <= "001";
- when x"55" => -- U
- led <= "00110";
- mode <= "011";
- when x"56" => -- V
- led <= "01110";
- mode <= "100";
- when x"57" => -- W
- led <= "00100";
- mode <= "011";
- when x"58" => -- X
- led <= "00110";
- mode <= "100";
- when x"59" => -- Y
- led <= "00100";
- mode <= "100";
- when x"5A" => -- Z
- led <= "00011";
- mode <= "100";
- when others =>
- led <= "00000";
- mode <= "000";
- end case;
- end case;
- end process;
- end Behavioral;
Add Comment
Please, Sign In to add comment