VHDL初探(三)之元件例化探讨

理论部分

一部分是元件声明部分,通常放在结构体声明部分;另一部分是元件例化部分,放在结构体描述部分。

元件声明

component 元件名 is
port(例化元件端口名表);
end component 元件名;

元件例化

例化名:元件名
	port map(元件端口=>当前实体端口,...,元件端口=>当前实体端口);

上述端口映射方式称为名称关联,即根据名称将相应的端口对应起来。
注:当顶层元件的端口、信号或参数排列顺序完全一致时,可以这样写:

port map(当前实体端口1,...,当前实体端口n);

实战部分

代码展示:

------------------half_adder.vhd----------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity half_adder is
	port(a,b: in std_logic;
	sum,carry:out std_logic
	);
end entity;

architecture rtl of half_adder is

	begin
	sum<=a xor b;
	carry<=a and b;
	end architecture;
	
--------------full_adder.vhd-----------------------------------
library ieee;
use ieee.std_logic_1164.all;

--定义实体
entity full_adder is
	port(a,b,cin: in std_logic;
			sum,carry: out std_logic
				);
end entity;

architecture rtl of full_adder is
	begin
	sum<=a xor b xor cin;--求两个一位的和
	carry<= (a and b) or (b and cin) or(cin and a);--计算进位值
end architecture;
	
----------------top.vhd------------------------------------------
library ieee;
use ieee.std_logic_1164.all;

entity top is
	port(A,B: in std_logic_vector(1 downto 0);
	sum: out std_logic_vector(1 downto 0);
	cout : out std_logic
	);
	end entity;
	
architecture structure of top is
---这部分完成元件声明
component half_adder is 
	port(A,B: in std_logic;
	Sum,Carry:out std_logic
	);
	end component;

component full_adder is
	port(A,B,Cin: in std_logic;
			Sum,Carry: out std_logic
	);
	end component;
	signal C: std_logic_vector(2 downto 0);
	--这部分进行元件例化
begin
	U0: half_adder port map(A=>A(0),B=>B(0),Sum=>sum(0),Carry=>C(0));
	U1: full_adder port map(A=>A(1),B=>B(1),Cin=>C(0),Sum=>sum(1),Carry=>cout);
	end structure;
	


注意:
1.对于元件例化部分的关联问题,要区分底层元件与顶层元件端口之间的关系,明确哪个量与哪个量之间的关系问题,这尤为重要。
2.要将top.vhd设置为顶层元件

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值