目的:实现一个8-3优先编码器。

8-3译码器真值表如下所示:
| 输入 | 输出 | |||||||||
| in7 | in6 | in5 | in4 | in3 | in2 | in1 | in0 | out2 | out1 | out0 |
| × | × | × | × | × | × | × | 1 | 1 | 1 | 1 |
| × | × | × | × | × | × | 1 | 0 | 1 | 1 | 0 |
| × | × | × | × | × | 1 | 0 | 0 | 1 | 0 | 1 |
| × | × | × | × | 1 | 0 | 0 | 0 | 1 | 0 | 0 |
| × | × | × | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| × | × | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| × | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
程序(两种方式实现)
(1)if...else语句
library ieee;
use ieee.std_logic_1164.all;
entity encoder is
port(
input :in std_logic_vector(7 downto 0);
output :out std_logic_vector(2 downto 0)
);
end encoder;
architecture behave of encoder is
begin
process(input)
begin
if(input(7) = '1') then output <= "111";
elsif(input(6) = '1') then output <= "110";
elsif(input(5) = '1') then output <= "101";
elsif(input(4) = '1') then output <= "100";
elsif(input(3) = '1') then output <= "011";
elsif(input(2) = '1') then output <= "010";
elsif(input(1) = '1') then output <= "001";
elsif(input(0) = '1') then output <= "000";
end if;
end process;
end behave;
波形仿真图

(2)when...else语句
library ieee;
use ieee.std_logic_1164.all;
entity encoder is
port(
input :in std_logic_vector(7 downto 0);
output :out std_logic_vector(2 downto 0)
);
end encoder;
architecture behave of encoder is
begin
output <= "111" when input(7) = '1' else
"110" when input(6) = '1' else
"101" when input(5) = '1' else
"100" when input(4) = '1' else
"011" when input(3) = '1' else
"010" when input(2) = '1' else
"001" when input(1) = '1' else
"000" when input(0) = '1' else
"ZZZ";
end behave;
波形仿真图

本文详细记录了使用VHDL语言实现8-3优先编码器的过程,包括真值表的展示及通过if...else语句和when...else语句两种方法的程序代码,并附有相应的波形仿真图。
2785

被折叠的 条评论
为什么被折叠?



