Advertisement
felipe4004

mux_7_seg_w_bin2bcd

Jun 4th, 2019
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.94 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company: UnB
  3. -- Aluno: Felipe R. Sobrinho
  4. -- Matrícula: 17/0141764
  5. -- Disciplina: Prática de Eetrônica 2 - 2019/1
  6. -- Professor: Gilmar Beserra
  7.  
  8. ----------------------------------------------------------------------------------
  9.  
  10.  
  11.  
  12. library IEEE;
  13. use IEEE.STD_LOGIC_1164.ALL;
  14. use IEEE.NUMERIC_STD.ALL;
  15. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  16.  
  17.  
  18. entity mux7seg is
  19.     Port ( clk : in STD_LOGIC;
  20.            dig : in STD_LOGIC_VECTOR(15 downto 0);
  21.            seg : out STD_LOGIC_VECTOR (6 downto 0);
  22.            an : out STD_LOGIC_VECTOR (3 downto 0));
  23. end mux7seg;
  24.  
  25. architecture Behavioral of mux7seg is
  26.     signal count : STD_LOGIC_VECTOR (1 downto 0) := "00";
  27.     signal number: STD_LOGIC_VECTOR (3 downto 0) := "0000";
  28.     signal dig_aux: STD_LOGIC_VECTOR (15 downto 0) := (others => '0');
  29.     signal in_binary: STD_LOGIC_VECTOR (7 downto 0);
  30.     signal digit_0  : STD_LOGIC_VECTOR (3 downto 0);
  31.     signal digit_1  : STD_LOGIC_VECTOR (3 downto 0);
  32.     signal digit_2  : STD_LOGIC_VECTOR (3 downto 0);
  33.     signal clk_7_segs: STD_LOGIC;
  34.  
  35.  
  36. begin
  37.  
  38. process(clk)
  39. variable counter: integer range 0 to 200000;
  40. begin
  41.     if rising_edge(clk)then
  42.     if counter=200000 then
  43.         clk_7_segs<=not(clk_7_segs);
  44.         counter:=0;
  45.     else
  46.         counter:= counter+1;
  47.     end if;
  48.     end if;
  49. end process;
  50.  
  51.  
  52.     process(in_binary)
  53.         variable s_digit_0 : unsigned( 3 downto 0);
  54.         variable s_digit_1 : unsigned( 3 downto 0);
  55.         variable s_digit_2 : unsigned( 3 downto 0);
  56.        
  57.         begin
  58.             s_digit_2 := "0000";
  59.             s_digit_1 := "0000";
  60.             s_digit_0 := "0000";
  61.          
  62.             for i in 7 downto 0 loop
  63.               if (s_digit_2 >= 5) then s_digit_2 := s_digit_2 + 3; end if;
  64.               if (s_digit_1 >= 5) then s_digit_1 := s_digit_1 + 3; end if;
  65.               if (s_digit_0 >= 5) then s_digit_0 := s_digit_0 + 3; end if;
  66.               s_digit_2 := s_digit_2 sll 1; s_digit_2(0) := s_digit_1(3);
  67.               s_digit_1 := s_digit_1 sll 1; s_digit_1(0) := s_digit_0(3);
  68.               s_digit_0 := s_digit_0 sll 1; s_digit_0(0) := in_binary(i);
  69.             end loop;
  70.          
  71.             digit_0 <=  std_logic_vector(s_digit_0);
  72.             digit_1 <=  std_logic_vector(s_digit_1);
  73.             digit_2 <=  std_logic_vector(s_digit_2);
  74.       end process;
  75.  
  76.  
  77.  
  78. dig_aux <= dig (15 downto 0);
  79.  
  80. anodo_process: process (clk_7_segs)
  81.     begin
  82.         if rising_edge (clk) then
  83.             count <= count +'1';
  84.             case count is
  85.                 when "00" =>
  86.                     an <= "1110";
  87.                     number <= digit_0;
  88.                    
  89.                 when "01" =>
  90.                     an <= "1101";
  91.                     number <= digit_1;
  92.                    
  93.                 when "10" =>
  94.                     an <= "1011";
  95.                     number <= digit_2;
  96.                    
  97.                 when "11" =>
  98.                     an <= "0111";
  99.                     number <= "0000";
  100.                     count <= "00";
  101.                 when others =>
  102.                     an <= "1111";
  103.                     count <= "00";
  104.            end case;
  105.        end if;
  106.     end process;
  107.    
  108.    
  109.     with number select --gfedcba
  110.       seg <=  "1000000" when "0000",
  111.               "1111001" when "0001",
  112.               "0100100" when "0010",
  113.               "0110000" when "0011",
  114.               "0011001" when "0100",
  115.               "0010010" when "0101",
  116.               "0000010" when "0110",
  117.               "1111000" when "0111",
  118.               "0000000" when "1000",
  119.               "0010000" when "1001",
  120.               "0100000" when "1010",
  121.               "0000011" when "1011",
  122.               "1000110" when "1100",
  123.               "0100001" when "1101",
  124.               "0000110" when "1110",
  125.               "0001110" when "1111",
  126.                (others=>'1') when others;
  127. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement