多路选择器VHDL
多路选择器的顶层电路如图所示。根据真值表,如果输入sel="01"或者sel=“10”,那么输出将等于对应的某一个输人(c=a或c=b)。然而如果输人sel="00"或者sel=“11”,那么输出将分别为0和Z(高阻)。
library ieee;
use ieee.std_logic_1164.all;
entity mux is
port (
a,b: in std_logic_vector(7 downto 0);
sel: in std_logic_vector(1 downto 0);
c: out std_logic_vector(7 downto 0)
);
end entity;
architecture example of mux is
begin
process (a,b,sel)
begin
if (sel="00")then
c <= "00000000";
elsif (sel="01")then
c <= a;
elsif (sel="10")then
c <= b;
else
c<= (others => 'Z');
end if;
end process;
end example;
注意代码最后赋值的高阻态Z要大写,参考书上说vhdl不区分大小写,但是我用小写会报如下错误,我也不知道为什么?有懂的大佬可以解释一下。
** Error: C:/Users/CLT/Desktop/test/D_NAND.vhd(23): Enumeration literal ‘z’ is type std.STANDARD.CHARACTER; expecting type ieee.std_logic_1164.STD_LOGIC.