实验内容

  1. 七段显示译码器设计(实验板上的数码管是共阳极的,低电平时点亮。) 输入:拨动开关,从“0000”至“1111”变化; 输出:用数码管显示(0,1,…9,A,b,C,d,E,F)。
  2. 8位二进制数加法器(用两个4位二进制数加法器实现层次化设计:元件例化,即在顶层调用。),用数码管显示(0,1,…9,A,b,C,d,E,F)
  3. 七人表决器设计。

1. 七段显示译码器设计

七段显示译码器功能:根据输入的4位二进制数在七段数码管上显示对应的十六位进制数。

利用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
25
26
27
28
29
30
31
library ieee;
use ieee.std_logic_1164.all;
entity seven is
port( a: in std_logic_vector(3 downto 0);
b: out std_logic_vector(6 downto 0));
end entity seven;

architecture behave of seven is
begin
p1:process(a)
begin
case a is
when"0000"=>b<="1000000";
when"0001"=>b<="1111001";
when"0010"=>b<="0100100";
when"0011"=>b<="0110000";
when"0100"=>b<="0011001";
when"0101"=>b<="0010010";
when"0110"=>b<="0000010";
when"0111"=>b<="1111000";
when"1000"=>b<="0000000";
when"1001"=>b<="0010000";
when"1010"=>b<="0001000";
when"1011"=>b<="0000011";
when"1100"=>b<="1000110";
when"1101"=>b<="0100001";
when"1110"=>b<="0000110";
when"1111"=>b<="0001110";
end case;
end process;
end architecture behave;

引脚配置:

img

实验设计与结果分析:

将4个开关作为输入,7个输出分别接七段数码管的7个输入端。

img

且数码管为共阳极。

将程序和引脚配置烧录到硬件中,拨动开关,从“0000”至“1111”变化,七段数码管相应显示0,1,…9,A,b,C,d,E,F的变化。

2. 8位二进制加法器(利用层次化设计)

8位二进制加法器功能:输入2个8位二进制数和1个进位输入,将三者相加得到相加和和进位输出。

利用VHDL编写实现8位二进制加法器设计:

add4:

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;

add8(例化add4组合得到add8):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
LIBRARY IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity add8 is
port(a8,b8:in std_logic_vector(7 downto 0);
ci8:in std_logic;
s8:out std_logic_vector(7 downto 0);
co8:out std_logic);
end entity;
architecture add_8 of add8 is
component 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 component;


signal c:std_logic;
begin

add8_1: add4
port map(a=>a8(3 downto 0),b=>b8(3 downto 0),s=>s8(3 downto 0),ci=>ci8,co=>c);

add8_2:add4
port map(a=>a8(7 downto 4),b=>b8(7 downto 4),s=>s8(7 downto 4),ci=>c,co=>co8);

end architecture add_8;

引脚配置:

img

实验设计与结果分析:

例化上次实验设计的2个四位二进制加法器,连接成一个八位二进制加法器。

低四位二进制加法器:

相加数输入连接八位二进制加法器的低四位输入,进位输入连接实际的进位输入端,相加和输出连接八位二进制加法器低四位的输出,进位输出连接高四位二进制加法器的进位输入。

高四位二进制加法器:

相加数输入对应八位二进制加法器的高四位输入,进位输入连接低四位二进制进位输出端,相加和输出连接八位二进制加法器高四位的输出,进位输出连接实际的进位输出端。

将两组共16个开关(每组8个)分别作为2个相加数的输入,另取一个开关作为进位输入。

取9个led,第一个作为进位输出显示,剩下8个作为相加和输出显示,亮为‘1’,灭为‘0’。

将程序和引脚配置烧录到硬件中,验证功能成功。

3. 七人表决器设计

七人表决器功能:

相当于七个人投票,票数超过半数,则亮灯通过;否则则灭灯不通过。

利用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
25
LIBRARY IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sum7 is
port (a:in std_logic_vector(7 downto 1);
b:out std_logic);
end entity;
architecture behave of sum7 is
begin
process(a)
variable sum: integer range 0 to 7;
begin
sum:=0;
if a(7)='1' then sum:=sum+1;end if;
if a(6)='1' then sum:=sum+1;end if;
if a(5)='1' then sum:=sum+1;end if;
if a(4)='1' then sum:=sum+1;end if;
if a(3)='1' then sum:=sum+1;end if;
if a(2)='1' then sum:=sum+1;end if;
if a(1)='1' then sum:=sum+1;end if;
if sum>3 then b<='1';
else b<='0';
end if;
end process;
end architecture;

引脚配置:

img

实验设计与结果分析:

将7个开关作为表决器,1个led为结果灯。

利用if语句对7个开关的状态进行计数,当7个开关中有4个及以上为‘1’状态时,led亮,即为表决通过;少于4个时,led不亮,即为表决不通过。

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