VHDL CODES
- 4:1 MUX USING IF ELSE STATEMENT
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity MUX41 is
Port ( I : in STD_LOGIC_VECTOR (03 downto 0);
SEL : in STD_LOGIC_VECTOR (01 downto 0);
Y : out STD_LOGIC);
end MUX41;
architecture Behavioral of MUX41 is
begin
PROCESS (I,SEL)
BEGIN
IF(SEL="00")THEN
Y<=I(0);
ELSIF(SEL="01")THEN
Y<=I(1);
ELSIF(SEL="10")THEN
Y<=I(2);
ELSE
Y<=I(3);
END IF;
END PROCESS;
end Behavioral;
2. 4:1 MUX USING CASE STATEMENT
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity mux41 is
Port ( I0 : in STD_LOGIC;
I1 : in STD_LOGIC;
I2 : in STD_LOGIC;
I3 : in STD_LOGIC;
SEL : in STD_LOGIC_VECTOR (01 downto 0);
Y : out STD_LOGIC);
end mux41;
architecture Behavioral of mux41 is
begin
PROCESS (I0,I1,I2,I3,SEL)
BEGIN
CASE SEL IS
WHEN "00"=>Y<=I0;
WHEN "01"=>Y<=I1;
WHEN "10"=>Y<=I2;
WHEN OTHERS=>Y<=I3;
END CASE;
END PROCESS;
end Behavioral;
3. 3:8 DECODER USING CASE STATEMENT
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity dec38 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
d : out STD_LOGIC_VECTOR (07 downto 0));
end dec38;
architecture Behavioral of dec38 is
signal enw:std_logic_vector(2 downto 0);
begin
enw<=a & b & c;
process(enw)
begin
case enw is
when"000"=>d<="00000001";
when"001"=>d<="00000010";
when"010"=>d<="00000100";
when"011"=>d<="00001000";
when"100"=>d<="00010000";
when"101"=>d<="00100000";
when"110"=>d<="01000000";
when"111"=>d<="10000000";
when others=>d<="00000000";
end case;