目的:设计并实现一个3-8译码器。
3-8译码器真值表如下所示:
in2 | in1 | in0 | out7 | out6 | out5 | out4 | out3 | out2 | out1 | out0 |
0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 |
0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 |
1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 |
1 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
程序设计(两种方法)
(1)case语句
library ieee;
use ieee.std_logic_1164.all;
entity decoder is
port(
input :in std_logic_vector(2 downto 0);
output :out std_logic_vector(7 downto 0)
);
end decoder;
architecture behave of decoder is
begin
process(input)
begin
case input is
when "000" => output <= "11111110";
when "001" => output <= "11111101";
when "010" => output <= "11111011";
when "011" => output <= "11110111";
when "100" => output <= "11101111";
when "101" => output <= "11011111";
when "110" => output <= "10111111";
when "111" => output <= "01111111";
when others => output <= "ZZZZZZZZ";
end case;
end process;
end behave;
仿真波形图
(2)with...select语句
library ieee;
use ieee.std_logic_1164.all;
entity decoder is
port(
input :in std_logic_vector(2 downto 0);
output :out std_logic_vector(7 downto 0)
);
end decoder;
architecture behave of decoder is
begin
with input select
output <= "11111110" when "000",
"11111101" when "001",
"11111011" when "010",
"11110111" when "011",
"11101111" when "100",
"11011111" when "101",
"10111111" when "110",
"01111111" when "111",
"ZZZZZZZZ" when others;
end behave;
波形仿真图