end Behavioral;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL; ENTITY rplcont IS
PORT(clk,clr:in std_logic;
count:out std_logic_vector(7 downto 0)); END rplcont;
ARCHITECTURE rtl OF rplcont IS
signal count_in_bar:std_logic_vector(8 downto 0); component dffr
port(clk,clr,d:in std_logic; q,qb:out std_logic); end component;
begin
count_in_bar(0)<=clk;
gen1:for i in 0 to 7 generate
u:dffr port map(clk=>count_in_bar(i), clr=>clr,d=>count_in_bar(i+1),
q=>count(i),qb=>count_in_bar(i+1)); end generate; end rtl;
(三) 测试向量设计
五、实验结果(仿真结果)与分析
36
实验五 综合实验
实验性质:综合性 实验级别:必做 开课单位:信息与通信工程学院通信工程系 学时:2学时 一、实验目的:
1、学习用VHDL语言实现比较大型的电路的方法。 2、继续巩固cpld技术层次化设计方法。
二、实验器材:
计算机、Quartus II软件或xilinx ISE 三、实验内容:
设计一数字时钟,要求具有时,分,秒,计数显示功能,以24小时循环计时;具有清零,调节小时,分钟功能;具有整点报时功能。 四、实验步骤:
1、根据电路特点,可在教师指导下用层次设计的概念,将此任务分成若干模块,规定每一模块的功能和各模块之间的接口。让几个学生分作和调试其中之一,然后再将各模块合起来联试。以培养学生之间的合作精神,同时加深层次化设计概念。
2、了解软件的元件管理深层含义,以及模块元件之间的连接概念,对于不同目录下的同一设计,如何融合。 3、模块说明:
各种进制的计数及时钟控制模块(10进制、6进制、24进制) 扫描分时显示,译码模块 各模块都用VHDL语言编写 参考程序
1、 秒模块 LIBRARY ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; ENTITY second IS PORT(
clk, reset,setmin : IN STD_LOGIC; enmin : OUT STD_LOGIC;
daout: out std_logic_vector (6 downto 0)); END entity second;
ARCHITECTURE fun OF second IS
SIGNAL count: STD_LOGIC_VECTOR( 6 downto 0);
37
BEGIN
daout <= count;
process ( clk , reset , setmin) begin
-- enmin<=k;
if (reset='0') then
count <= \ elsif (setmin='0') then enmin <= clk;
elsif (clk 'event and clk='1') then
if (count(3 downto 0)=\ if (count <16#60#) then
if (count=\ enmin<='1';
count<=\ ELSE
count<=count+7; end if; else
count<=\ end if;
elsif (count < 16#60#) then count <= count+1;
enmin<='0' after 100 ns; else
count<=\ end if; end if; end process; END fun;
分钟模块和小时模块参考秒模块。 2、 设定时间 LIBRARY ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; ENTITY seltime IS PORT(
clk1, reset: IN STD_LOGIC;
sec,min : IN STD_LOGIC_VECTOR(6 downto 0); hour : in std_logic_vector (5 downto 0);
daout : OUT STD_LOGIC_vector (3 downto 0); sel : out std_logic_vector ( 2 downto 0)); END seltime;
ARCHITECTURE fun OF seltime IS
SIGNAL count: STD_LOGIC_vector ( 2 downto 0);
38
BEGIN
sel <= count;
process ( clk1,reset) begin
if (reset ='0') then count <= \
elsif (clk1 'event and clk1='1') then if ( count >= \ count <= \ else
count <= count + 1; end if; end if; case count is
when \ when \
daout(2 downto 0) <= sec (6 downto 4); when \ when \
daout(2 downto 0) <= min (6 downto 4); when \ when others => daout(3 downto 2) <= \
daout(1 downto 0) <= hour(5 downto 4); end case; end process; end fun; 3、 显示模块 LIBRARY ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; ENTITY alert IS PORT(
clk : IN STD_LOGIC;
dain : IN STD_LOGIC_VECTOR(6 DOWNTO 0); speak: OUT STD_LOGIC;
lamp : OUT STD_LOGIC_VECTOR(2 DOWNTO 0)); END alert ;
ARCHITECTURE fun OF alert IS
signal count : std_logic_vector( 1 downto 0); signal count1: std_logic_vector( 1 downto 0);
BEGIN
speaker:process (clk) begin
speak <= count1(1);
if (clk 'event and clk= '1') then
39
if (dain = \
if (count1>=\ count1<=\ else
count1 <= count1 + 1; end if; end if; end if;
end process speaker; lamper:process(clk) begin
if (rising_edge(clk))then if (count <= \ if (count =\ lamp <= \
elsif (count = \ lamp <= \ elsif(count=\ lamp <= \ end if;
count <= count + 1; else
count <= \ end if; end if; end process lamper; END fun ;
(三) 测试向量设计
五、实验结果(仿真结果)与分析
40