WITH state SELECT --在调时的小时,闪烁数码管—的时 flashhour <= '1' WHEN adj_hour0 | adj_hour1, '0' when others; WITH state SELECT --在调时的分,闪烁数码管—的分 flashmin <= '1' WHEN adj_min0 | adj_min1, '0' when others; end s_machine;
§4.3 上机实验:
利用MAX+PLUSII软件的VHDL综合器实现如下题目:
题目:设计一个模为60的8421BCD计数器,并用数码管显示。
将其分解为一个模为60的8421BCD计数器及一个七段译码器,将计数器及译码器编译到库中,之后用元件例化来实现顶层设计。
·设计模为60的8421BCD计数器
选择File/New出现选择对话框,选择Text Editor File输入如下文本,并保存为 cntm60.vhd注意保存时选择vhd的文件后缀且文件名必须与实体名相同。 ---《文件清单见第二节的例子。》
将此文件设为当前项目(File/Project/Set Project to Curreent File)后编译,之后建立模拟文件cntm60.scf来仿真此计数器。
·设计七段译码器 文件名decode47.vhd
library ieee;
use ieee.std_logic_1164.all; entity decode47 is port (adr :in std_logic_vector(3 downto 0); decodeout :out std_logic_vector(6 downto 0)); end decode47;
architecture truthtable of decode47 is begin
165
.
process(adr) begin
case adr is
when \ when \ when \ when \ when \ when \ when \ when \ when \ when others=> decodeout<= \ end case; end process; end truthtable;
·建立程序包
将上面设计的计数器,译码器定义到程序包cntpkg中,以便其他程序调用。
library ieee;
use ieee.std_logic_1164.all;
PACKAGE cntpkg IS -- Component Declaration Component cntm60 IS PORT ( ci : IN std_logic; nreset : IN std_logic; load : IN std_logic; d : IN std_logic_vector(7 downto 0); clk : IN std_logic; co : out std_logic; qh : buffer std_logic_vector(3 downto 0); ql : buffer std_logic_vector(3 downto 0) );
end Component;
Component decode47 is port
(adr: in std_logic_vector(3 downto 0);
decodeout:out std_logic_vector(6 downto 0));
166
.
end Component;
END cntpkg;
将其保存为cntpkg.vhd后,执行File/Project/Save& Compile命令来编译此程序包。
·顶层设计
以元件调用方式实现设计。建立顶层文件cnt.vhd如下:
library train; --用户自建库 use train.cntpkg.all;
library IEEE;
use IEEE.std_logic_1164.all;
entity cnt IS port
( nreset,load,ci,clk:in std_logic;
d : in std_logic_vector(7 downto 0); co : out std_logic; q1 : out std_logic_vector(6 downto 0); q2 : out std_logic_vector(6 downto 0)); end cnt;
ARCHITECTURE arch OF cnt IS
signal qa,qb : std_logic_vector(3 downto 0); BEGIN
u1:cntm60 port map(ci,nreset,load,d,clk,co,qa,qb); u2:decode47 port map(qa,q1); u3:decode47 port map(qb,q2);
END arch;
其最上面两行 library train;
use train.cntpkg.all;
其中train为库名,实际就是一个目录,它包含用户设计的文件。库名与目录名的对应关系可在如下对话框中设定。(在项目编译状态下,即打开Compiler对话框时,选择菜单命令Interfaces/VHDL Netlist Reader Settings…即可打开此对话框)。use语句使库train的程序包cntpkg中所有(all)的内容对下面的设计都可见,亦即刚才设计的计数器,译码器可在下面的设计中被调用。
167
.
将此文件cnt.vhd设为当前项目文件,并选择器件EPM7128-15,锁定管脚在实验板上模拟,也可建立模拟文件来仿真。
168
.