2 to 4 decoder
entity dec2to4 is
Port ( enable : in STD_LOGIC;
sw : in STD_LOGIC_VECTOR (1 downto 0);
led : out STD_LOGIC_VECTOR (3 downto 0));
end dec2to4;
architecture Behavioral of dec2to4 is
begin
led <= "0000" when enable='0' else
"0001" when sw="00" else
"0010" when sw="01" else
"0100" when sw="10" else
"1000";
end Behavioral;
3 to 8 dcoder using 2 to 4
ibrary 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 leaf cells in this code.
--library UNISIM;
--use [Link];
entity DEC_38 is
Port ( w : in STD_LOGIC_VECTOR (2 downto 0);
EN : in STD_LOGIC;
Y : out STD_LOGIC_VECTOR (7 downto 0));
end DEC_38;
architecture Behavioral of DEC_38 is
component dec2to4 is
Port ( enable : in STD_LOGIC;
sw : in STD_LOGIC_VECTOR (1 downto 0);
led : out STD_LOGIC_VECTOR(3 downto 0));
end component;
signal m0: STD_LOGIC;
signal m1: STD_LOGIC;
begin
U1: dec2to4 Port map(m1,w(1 downto 0),Y(7 downto 4));
U2: dec2to4 Port map(m0,w(1 downto 0),Y(3 downto 0));
m0 <= NOT w(2) AND EN;
m1 <= w(2) AND EN;
end behavioral;
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 leaf cells in this code.
--library UNISIM;
--use [Link];
entity dec2 is
Port ( i : in STD_LOGIC_VECTOR (1 downto 0);
en : in STD_LOGIC;
y : out STD_LOGIC_VECTOR (7 downto 0));
end dec2;
architecture Behavioral of dec2 is
component decoder1
Port ( a : in STD_LOGIC_VECTOR (1 downto 0);
e: in STD_LOGIC;
b : out STD_LOGIC_VECTOR (3 downto 0));
end component;
signal ebar: std_logic;
begin
U1: decoder1 Port map(i(1 downto 0),EN,y(7 downto 4));
U2: decoder1 Port map(i(1 downto 0), ebar,y(3 downto 0));
ebar <= not en;
end Behavioral;