四选一数据选择器源程序.doc
文本预览下载声明
四选一数据选择器源程序
Library ieee;
Use ieee.std_logic_1164.all;
Entity mux4_2 is
Port (din: in std_logic_vector(3 downto 0);
a,b : in std_logic;
S: out std_logic);
End;
Architecture with_when of mux4_2 is
Signal sel : std_logic_vector(1 downto 0);
Begin
Sel=ab;
S=din(0) when sel=“00”else
din(1)when sel= “01” else
din(2)when sel= “10” else
din(3);---见程序说明。
Architecture with_select of mux4 is
Signal sel :std_logic_vector(1 downto 0);
begin
sel=ab;
with sel select
s=din(0) when “00”,
s=din(1) when “01”,
s=din(2) when “10”,
s=din(3) when “11”,
‘Z’when others;
End;
程序说明:
本程序中含有两个结构体,with_when和 with_select,max+plus软件系统自动执行几何位置处于最后的机构体with_select.
结构体with_when是用并行条件信号赋值语句描述四选一数据选择器。注意,最后一个输出din(3)不含有when子句;在s表达式中只有一个分号(;)。
结构体with_select.是用并行选择信号赋值语句描述四选一数据选择器。注意,选择信号赋值语句中选择条件与case语句相似,不允许条件重叠和涵盖不全。由于a,b的值除了‘1’‘0’外,还有其他7个值,所以要用when others代表其他值,以穷尽所有可能值。
同一个设计任务,可以用不同的语句进行描述,
本程序中din为输入4位矢量信号。
实例2 3线----8线译码器
设计任务
描述一个3线-8线译码器,使能端为g1、g2a、g3b,地址选择端为a、b、c,输出端为总线y。
算法设计
用case语句描述电路,利用真值表辅助,很容易编写出程序。
源程序
文件名 decoder3_8.vhd
端口图
3线-8线译码器端口
源程序
Library ieee;
Use ieee.std_logic_1164.all;
Entity decoder3_8 is
Port (a、b、c g1、g2a、g2b:in std_logic;
Y: out std_logic_vector(7 downto 0));
End;
Architecture rtl of decoder3_8 is
Signal dz:std_logic_vector(2 downto 0);
Begin
Dz=cba;
Process(dz,g1,g2a,g3b)
Begin
If (g1= ‘1’ and g2a= ‘0’and g2b= ‘0’) then
Case dz is
When “000”=y= ;
When “001”=y= ;
When “010”=y= ;
When “011”=y= “111101111”;
When “100”=y= ;
When “101”=y= ;
When “110”=y= ;
When “111”=y= ;
When others =y= “XXXXXXXX”;
End case;
Else
Y= ;
End if ;
End process;
End;
a
b
c
g1 y[7..0]
g2a
g2b
显示全部