"); //-->
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;
USE ieee.std_logic_arith.all;
ENTITY decoder3_8 IS
PORT
(
g1,g2a,g2b: IN STD_LOGIC; --使能输入信号
a,b,c: IN STD_LOGIC; --地址输入信号
y: OUT STD_LOGIC_VECTOR (7 DOWNTO 0) --输出信号
);
END decoder3_8;
ARCHITECTURE Art1 OF decoder3_8 IS
SIGNAL comb:STD_LOGIC_VECTOR (2 DOWNTO 0); --定义信号comb,是3bits的
BEGIN
comb <= c&b&a;
PROCESS(comb,g1,g2a,g2b)
BEGIN
IF (g1 = '1' AND g2a = '0' AND g2b = '0') THEN
CASE comb IS --使能有效时,进行地址译码
WHEN "000" => Y <= "11111110";
WHEN "001" => Y <= "11111101";
WHEN "010" => Y <= "11111011";
WHEN "011" => Y <= "11110111";
WHEN "100" => Y <= "11101111";
WHEN "101" => Y <= "11011111";
WHEN "110" => Y <= "10111111";
WHEN "111" => Y <= "01111111";
WHEN OTHERS => Y <= "11111111";
END CASE;
ELSE Y <= "11111111"; --使能无效时,输出无效(高电平)
END IF;
END PROCESS;
END Art1;
ARCHITECTURE Art2 OF decoder3_8 IS
SIGNAL input,en:STD_LOGIC_VECTOR (2 DOWNTO 0); --定义信号input,en:是3bits的
BEGIN
input <= c & b & a;
en <= g1 & g2a & g2b;
PROCESS(input,en)
Variable temp: std_logic_vector(7 downto 0);
BEGIN
IF (en = B"100") THEN --使能有效时,进行地址译码
--temp := B"0000_0001" SLL conv_integer(input); --经验证,Quartus II 不支持移位操作SLL,……
--temp := B"0000_0" & input;
temp := B"0000_0" & (conv_std_logic_vector(conv_integer(input),3)); --经验证,这里的2个转换函数都是正确的
Y <= NOT temp; --经验证,实现了对temp逐位取反,是正确的
ELSE
Y <= B"1111_1111"; --使能无效时,输出无效(高电平)
END IF;
END PROCESS;
END Art2;
CONFIGURATION decoder3_8_Sel_01 OF decoder3_8 IS
FOR Art1 --该行语句如果写成“FOR Art2”表示选择“过程体Art2”
END FOR;
END CONFIGURATION decoder3_8_Sel_01;
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。