Advertisement
Guest User

display.vhd

a guest
Mar 13th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.27 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    12:29:51 03/05/2019
  6. -- Design Name:
  7. -- Module Name:    Lab6 - 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. use IEEE.STD_LOGIC_ARITH.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24.  
  25.  
  26. ---- Uncomment the following library declaration if instantiating
  27. ---- any Xilinx primitives in this code.
  28. --library UNISIM;
  29. --use UNISIM.VComponents.all;
  30.  
  31. entity Lab6 is
  32. port(  
  33.     signal clk_i : in std_logic;
  34.     signal led7_an_o : out std_logic_vector(3 downto 0);
  35.     signal led7_seg_o : out std_logic_vector(7 downto 0);
  36.     signal sw_i : in std_logic_vector(7 downto 0);
  37.     signal btn_i : in std_logic_vector(3 downto 0)
  38.     );
  39. end Lab6;
  40.  
  41. architecture Behavioral of Lab6 is
  42.  
  43.     signal digit_i : std_logic_vector(31 downto 0):=(others => '1');
  44.     signal clk_d : std_logic;
  45.    
  46.     component divider
  47.     Port (
  48.         signal clk_i : in std_logic;
  49.       signal clk_o : out std_logic);
  50.     end component;
  51.    
  52.     function digit(sw : in std_logic_vector(3 downto 0)) return std_logic_vector is
  53.     begin
  54.         case sw is
  55.             when "0000" => return ("0000001");
  56.             when "0001" => return ("1001111");
  57.             when "0010" => return ("0010010");
  58.             when "0011" => return ("0000110");
  59.             when "0100" => return ("1001100");
  60.             when "0101" => return ("0100100");
  61.             when "0110" => return ("0100000");
  62.             when "0111" => return ("0001111");
  63.             when "1000" => return ("0000000");
  64.             when "1001" => return ("0000100");
  65.             when "1010" => return ("0000010");
  66.             when "1011" => return ("1100000");
  67.             when "1100" => return ("0110001");
  68.             when "1101" => return ("1000010");
  69.             when "1110" => return ("0110000");
  70.             when others => return ("0111000");
  71.         end case;
  72.     end function digit;
  73.        
  74. BEGIN
  75.  
  76.     div:divider
  77.     port map (  clk_i => clk_i,
  78.                     clk_o => clk_d);
  79.    
  80.     process(clk_d)
  81.     variable counter : integer := 0;
  82.     begin
  83.     if rising_edge(clk_d) then
  84.         --AN3
  85.         if btn_i(3) = '1' then
  86.                 digit_i(31 downto 25) <= digit(sw_i(3 downto 0));
  87.         end if;
  88.         -- AN2
  89.         if btn_i(2) = '1' then
  90.                 digit_i(23 downto 17) <= digit(sw_i(3 downto 0));
  91.         end if;
  92.         -- AN1
  93.         if btn_i(1) = '1' then
  94.                 digit_i(15 downto 9) <= digit(sw_i(3 downto 0));
  95.         end if;
  96.         -- AN0
  97.         if btn_i(0) = '1' then
  98.                 digit_i(7 downto 1) <= digit(sw_i(3 downto 0));
  99.         end if;
  100.         digit_i(24) <= not sw_i(7);
  101.         digit_i(16) <= not sw_i(6);
  102.         digit_i(8) <= not sw_i(5);
  103.         digit_i(0) <= not sw_i(4);
  104.        
  105.             if counter = 4 then
  106.             counter := 0;
  107.             elsif counter = 0 then
  108.             led7_seg_o <= digit_i(31 downto 24);
  109.             led7_an_o <= "0111";
  110.             counter := counter +1;
  111.             elsif counter = 1 then
  112.             led7_seg_o <= digit_i(23 downto 16);
  113.             led7_an_o <= "1011";
  114.             counter := counter +1;
  115.             elsif counter = 2 then
  116.             led7_seg_o <= digit_i(15 downto 8);
  117.             led7_an_o <= "1101";
  118.             counter := counter +1;
  119.             elsif counter = 3 then
  120.             led7_seg_o <= digit_i(7 downto 0);
  121.             led7_an_o <= "1110";
  122.             counter := counter +1;
  123.             end if;
  124.     end if;
  125.     end process;
  126.    
  127. END Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement