VHDL——74LS138译码器

1.功能描述

功能描述:该3-8译码器有六个输入端:S1,S2,S3为控制信号,a0,a1,a2为三个输入信号。一个输出端口y为八位总线,表示译码结果。

2.真值表

3.VHDL语言
3.1case语句

library ieee;
use ieee.std_logic_1164.all;

entity decode38 is
    port(a,b,c,g1,g2a,g2b : in std_logic;
	     y : out std_logic_vector(7 downto 0));
end decode38;

architecture rtl of decode38 is
signal indata : std_logic_vector(2 downto 0);
begin
    indata <= c&b&a;
process(indata,g1,g2a,g2b)
begin
    if(g1 = '1' and g2a = '0' and g2b = '0')then
	 case indata 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 <= null;      --输入其他数据,y指向空
	 end case;
    else
	 y <= "11111111";
	 end if;
end process;
end rtl;
	 

3.2if语句

library ieee;
use ieee.std_logic_1164.all;

entity decode38 is
    port(a,b,c,g1,g2a,g2b : in std_logic;
	     y : out std_logic_vector(7 downto 0));
end decode38;

architecture rtl of decode38 is
signal indata : std_logic_vector(2 downto 0);
begin
    indata <= c&b&a;
process(indata,g1,g2a,g2b)
begin
    if(g1 = '1' and g2a = '0' and g2b = '0')then
	   if(indata = "000") then y <= "11111110";
	   elsif(indata = "001") then y <= "11111101";
	   elsif(indata = "010") then y <= "11111011";
	   elsif(indata = "011") then y <= "11110111";
	   elsif(indata = "100") then y <= "11101111";
	   elsif(indata = "101") then y <= "11011111";
	   elsif(indata = "110") then y <= "10111111";
	   elsif(indata = "111") then y <= "01111111";
	   else
	   y <= null;
	   end if;
    else
	 y <= "11111111";
	 end if;
end process;
end rtl;
	 
  • 4
    点赞
  • 55
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
3-8译码器是一种逻辑电路,用于将3位二进制输入码转换为8位二进制输出码。在VHDL中,我们可以使用结构描述方法来实现3-8译码器。 首先,我们需要定义输入和输出信号。输入信号是一个3位二进制码,可以使用一个std_logic_vector(2 downto 0)类型的变量来表示。输出信号是一个8位二进制码,可以使用一个std_logic_vector(7 downto 0)类型的变量来表示。 接下来,我们需要使用内部信号来实现译码功能。我们可以使用一个case语句来对输入进行译码,并将对应的输出信号设置为'1',其他输出信号设置为'0'。 以下是一个简单的3-8译码器的VHDL代码示例: ```vhdl library ieee; use ieee.std_logic_1164.all; entity decoder_3to8 is port( input : in std_logic_vector(2 downto 0); output : out std_logic_vector(7 downto 0) ); end entity decoder_3to8; architecture Behavioral of decoder_3to8 is begin process(input) begin case input is when "000" => output <= "00000001"; when "001" => output <= "00000010"; when "010" => output <= "00000100"; when "011" => output <= "00001000"; when "100" => output <= "00010000"; when "101" => output <= "00100000"; when "110" => output <= "01000000"; when "111" => output <= "10000000"; when others => output <= "00000000"; end case; end process; end architecture; ``` 这段代码中,我们使用一个case语句来对输入进行译码,并将对应的输出位置为'1',其他输出位置为'0'。对于无法识别的输入,将所有输出位置为'0'。 以上是一个简单的3-8译码器的VHDL实现。通过使用结构描述方法,我们可以清晰地描述译码器的行为,并实现所需的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

364.99°

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值