background image

3 用 vhdl 语言 if 语句来实现 2 选 1 数据选择器

ibrary ieee;

use ieee.std_logic_1164.all;

entity choose is

port (d0;d1,sel : in std_logic;

y : out std_logic );

end choose ;

architecture arc of choose is

begin process(d0,d1,sel)

begin 

if (sel <= ‘1’) then 

  y <= d1;

else y <= d0 ;

end if ;

end process ;

end arc;

4 用 VHDL 实现 3-8 译码器

ibrary ieee;

use ieee.std_logic_1164.all;

entity encoder is

port ( a : in std_logic_vector ( 2 downto 0 );

b : out std_logic_vector ( 7 downto 0));

end encoder ;

architecture behav of encoder is 

signal indata : std_logic_vector ( 2 downto 0 );

begin 

process (a)

begin 

indata <= a(2)&a(1)&a(0);

case indata is

when “000”=>b<=”00000001”;

when “001”=>b<=”00000010”;

when “010”=>b<=”00000100”;

when “011”=>b<=”00001000”;

when “100”=>b<=”00010000”;

when “101”=>b<=”00100000”;

when “110”=>b<=”01000000”;

when “111”=>b<=”10000000”;

when others =>b<=”XXXXXXXX”;

end case ;

end process ;

end behav ;