实验内容

  1. 4选1数据选择器的设计(图形和文本);
  2. 四位比较器;
  3. 四位二进制数加法器。

1. 4选1数据选择器的设计(图形和文本)

①运用元器件直接连接得到4选1数据选择器:

img

②利用VHDL编写实现4选1数据选择器:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
library ieee;
use ieee.std_logic_1164.all;
entity mux_41 is
  port(
                        s :  in std_logic_vector(1 downto 0);
                         y :  out std_logic);
end entity mux_41;
architecture archmux of mux_41 is
 begin
     mux4_1: process (s)
       begin
           if     s = "00" then   y <= '1';
           elsif  s = "01" then   y <= '0';
           elsif  s = "10" then   y <= '1';
           else   y <= '0';
           end if;
     end process mux4_1;
end architecture archmux;

引脚配置:

img

实验设计与结果分析:将两种方法做出的4选1数据选择器分别烧录到板子上,实现的功能完全一致,用两个开关控制输入,用一个绿色led显示输出。

当开关为“00”时,绿灯亮;

当开关为“01”时,绿灯灭;

当开关为“10”时,绿灯亮;

当开关为“11”时,绿灯灭。

2. 四位比较器

四位比较器功能:输入2个四位二进制数,进行比较,输出比较结果。

运用VHDL编写实现四位比较器:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
library ieee;
use ieee.std_logic_1164.all;
entity mv4 is
   port (   a : in std_logic_vector(3 downto 0);
               b : in std_logic_vector(3 downto 0);
    bt,st,eq : out std_logic);
end entity mv4;
architecture behave of mv4 is
begin
 p1 : process (a,b)
    begin
       if     (a>b) then bt<='1';eq<='0';st<='0';
       elsif (a<b)  then bt<='0';eq<='0';st<='1';
       elsif (a=b) then  bt<='0';eq<='1';st<='0';
             end if;
 end process p1;
end architecture behave;

引脚配置:

img

实验设计与结果分析:

实验中将两组共8个开关(每组4个开关)作为2个四位二进制数的输入。

输出有:bt、eq、st分别为a>b、a=b、a<b的输出信号。

将程序及引脚配置烧录到硬件中验证,结果正确。

3. 四位二进制数加法器

四位二进制加法器功能:将输入的2个四位二进制加法器和进位输入相加,得到相加和和进位输出。

运用VHDL编写实现四位二进制加法器:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
LIBRARY IEEE;
use ieee.std_logic_1164.all;

entity add4 is
port(a,b:in std_logic_vector(3 downto 0);
ci:in std_logic;
s:out std_logic_vector(3 downto 0);
co:out std_logic);
end entity;
architecture add_4 of add4 is
SIGNAL c0,c1,c2:std_logic;
begin
s(0) <= a (0) xor b(0) xor ci;
c0<= (a(0) and b(0)) or (a(0) and ci) or (b(0) and ci);

s(1) <= a (1) xor b(1) xor c0;
c1<= (a(1) and b(1)) or (a(1) and c0) or (b(1) and c0);

s(2) <= a (2) xor b(2) xor c1;
c2<= (a(2) and b(2)) or (a(2) and c1) or (b(2) and c1);

s(3) <= a (3) xor b(3) xor c2;
co<= (a(3) and b(3)) or (a(3) and c2) or (b(3) and c2);
end architecture add_4;

引脚配置:

img

实验设计与结果分析:

实验模块设计中,将两组共8个开关(每组4个开关)作为2个四位二进制数的输入,另取一个开关作为进位输入。取5个led灯,第一个作为进位输出,剩下4个作为相加和的输出。

将程序和引脚配置烧录至硬件中,验证正确。