【VHDL语言学习笔记(五)】 编码器

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

8-3译码器真值表如下所示:

8-3译码器真值表
输入输出
in7in6in5in4in3in2in1in0out2out1out0
×××××××1111
××××××10110
×××××100101
××××1000100
×××10000011
××100000010
×1000000001
10000000000

程序(两种方式实现)

(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;	

波形仿真图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

单片机学习之路

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

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

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

打赏作者

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

抵扣说明:

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

余额充值