VHDL语言实现编码器译码器数据选择器
1. 编码器
1.1 实验要求
设计4-16译码器
- 具有使能端。使能端有效时,译码器根据输入状态,使输出通道中相应的一路有信号输出(为‘0’),其余为‘1’;
- 使能端无效时,译码器被禁止,所有输出无效(为‘1’)。
1.2 逻辑符号
1.3 实现代码
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity decoder is
port(
ein : in std_logic; -- 使能端
cin : in std_logic_vector(3 downto 0); -- 4位输入
cout : out std_logic_vector(15 downto 0) -- 16位输出
);
end decoder;
architecture decoder_1 of decoder is
signal temp:std_logic_vector(15 downto 0);
begin -- 使能端输入为1有效 结果输出0有效 1无效
temp <= "1111111111111110" when(ein='1' and cin="0000") else
"1111111111111101" when(ein='1' and cin="0001") else
"1111111111111011" when(ein='1' and cin="0010") else
"1111111111110111" when(ein='1' and cin="0011") else
"1111111111101111" when(ein='1' and cin="0100") else
"1111111111011111" when(ein='1' and cin="0101") else
"1111111110111111" when(ein='1' and cin="0110") else
"1111111101111111" when(ein='1' and cin="0111") else
"1111111011111111" when(ein='1' and cin="1000") else
"1111110111111111" when(ein='1' and cin="1001") else
"1111101111111111" when(ein='1' and cin="1010") else
"1111011111111111" when(ein='1' and cin="1011") else
"1110111111111111" when(ein='1' and cin="1100") else
"1101111111111111" when(ein='1' and cin="1101") else
"1011111111111111" when(ein='1' and cin="1110") else
"0111111111111111" when(ein='1' and cin="1111") else
"1111111111111111";
cout <= temp;
end architecture;
1.4 仿真测试
2. 译码器
2.1 实验要求
设计BCD码编码器
- 具有使能端。使能端有效时,编码器处于正常工作状态,根据输入(10个数码之一),产生4位输出。
2.2 逻辑符号
2.3 实现代码
library ieee;
use ieee.std_logic_1164.all;
entity encoder is
port(
ein:in std_logic;-- 高电平有效
cin:in std_logic_vector(9 downto 0);-- 高电平有效
cout:out std_logic_vector(3 downto 0) -- 4位输出
);
end encoder;
architecture encoder_1 of encoder is
signal temp:std_logic;
begin
process(ein,cin)
begin
if ein='1' then
if cin(9)='1' then cout <= "1001";
elsif cin(8)='1' then cout <= "1000";
elsif cin(7)='1' then cout <= "0111";
elsif cin(6)='1' then cout <= "0110";
elsif cin(5)='1' then cout <= "0101";
elsif cin(4)='1' then cout <= "0100";
elsif cin(3)='1' then cout <= "0011";
elsif cin(2)='1' then cout <= "0010";
elsif cin(1)='1' then cout <= "0001";
elsif cin(0)='1' then cout <= "0000";
else cout <= "0000";
end if;
else cout <= "0000";
end if;
end process;
end architecture;
2.4 仿真测试
3. 数据选择器
3.1 实验要求
设计4路数据选择器
- 输入:4个数据,每个数据是16位的二进制数;选择控制端2位,根据控制端的二进制编码,从4个输入数据中选择一个需要的数据送到输出端;
- 使能端,当使能端有效时,输入的4个数据中的某个数据输送到输出端,
- 当使能端无效时,输出为高阻态“ZZZZZZZZZZZZZZZZ”。
- 输出:一个16位的二进制数或者高阻态。
3.2 逻辑符号
3.3 实现代码
library ieee;
use ieee.std_logic_1164.all;
entity selector is
port(
ein:in std_logic;-- 使能端 高电平有效
d0,d1,d2,d3:in std_logic_vector(15 downto 0);
cin:in std_logic_vector(1 downto 0);
cout:out std_logic_vector(15 downto 0)
);
end selector;
architecture selector_1 of selector is
begin
process(cin,d0,d1,d2,d3,ein)
begin
if ein='1' then
case cin is
when "00" => cout <= d0;
when "01" => cout <= d1;
when "10" => cout <= d2;
when "11" => cout <= d3;
when others => cout <= "ZZZZZZZZZZZZZZZZ";
end case;
else cout <= "ZZZZZZZZZZZZZZZZ";
end if;
end process;
end architecture;
3.4 仿真测试
——————END-2022-05-22——————