summaryrefslogtreecommitdiff
path: root/FPGA/vhdl/seven_segment_decoder.vhd
blob: 8852319b90d1655076b54c699d945e102cda03c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-------------------------------------------
-- decodeur 7 segments
-------------------------------------------
-- ESIEE
-- Creation     : A. Exertier, novembre 2004
-- Modification : A. Exertier, decembre 2011
-------------------------------------------

library ieee;
use ieee.std_logic_1164.all;
---------------------------------------------------
--            Parametre generique
---------------------------------------------------
-- active_low : true  => segment allume par 0
--              false => segment allume par 1
---------------------------------------------------
--           Entrees/sorties
---------------------------------------------------
-- hexa 	    : entree code hexadacimal (4 bits)
-- abcdefg   : sortie 7 segments
--		a : segment horizontal superieur
--      a est le MSB de abcdefg
--		b : segment vertical superieur droit
--		c : segment vertical inferieur droit
--		d : segment horizontal inferieur
--		e : segment vertical indefieur gauche
--		f : segment vertical superieur gauche
--		g : segment horizontal milieu
---------------------------------------------------

entity seven_segment_decoder  is
  generic (active_low : boolean := true);
  port (hexa    : in  std_logic_vector(3 downto 0);
        hex     : out std_logic_vector(6 downto 0));
end ;


architecture RTL of  seven_segment_decoder is
  signal segments : std_logic_vector(hex'range);
  signal abcdefg  : std_logic_vector(hex'range);
begin
 abcdefg <= segments when active_low else  not segments;
 process(abcdefg) is
 begin
   for i in hex'range loop
	   hex(i) <= abcdefg(hex'length-1-i);
	end loop;
 end process;
 
 process(hexa)
 begin
  case hexa is
    when "0000" => segments <= "0000001";  -- 0
    when "0001" => segments <= "1001111";  -- 1
    when "0010" => segments <= "0010010";  -- 2
    when "0011" => segments <= "0000110";  -- 3
    when "0100" => segments <= "1001100";  -- 4
    when "0101" => segments <= "0100100";  -- 5
    when "0110" => segments <= "0100000";  -- 6
    when "0111" => segments <= "0001111";  -- 7
    when "1000" => segments <= "0000000";  -- 8
    when "1001" => segments <= "0000100";  -- 9
    when "1010" => segments <= "0001000";  -- A
    when "1011" => segments <= "1100000";  -- B
    when "1100" => segments <= "0110001";  -- C
    when "1101" => segments <= "1000010";  -- D
    when "1110" => segments <= "0110000";  -- E
    when "1111" => segments <= "0111000";  -- F
    when others => segments <= "1111111";
  end case;
 end process;
end ;