VHDL数字时钟实验报告
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
VHDL数字时钟设计
一、实验目的:
进一步练习VHDL语言设计工程的建立与仿真的步骤和方法、熟悉VHDL语言基本设计实体的编写方法。同时,在已有知识的基础上,简单综合编写程序,仿制简单器械。
二、实验环境:
PC个人计算机、Windows XP操作系统、Quartus II集成开发环境软件。
三、设计要求:
运用VHDL语言编写一个数字钟,具体要求:
1. 具有时、分、秒计数的十进制数字显示功能,以24小时循环计时。
2. 具有手动调节小时,分钟的功能。
3. 具有闹钟的功能,能够在设定的闹钟时间发出闹铃声。
四、实验步骤:
1. 定义输入输出信号量
port(
clk:in std_logic; ---时钟
speak:out std_logic; ---铃
dout:out std_logic_vector(7 downto 0); ---晶体管显示
setclk:in std_logic_vector(2 downto 0); ---操作按钮
d1,d2,d3,d4,d5,d6: out std_logic); ---六个晶体管
2. 定义结构体中的信号量
signal sel:std_logic_vector(2 downto 0);
signal hou1:std_logic_vector(3 downto 0); --时分秒的个位和十位
signal hou2:std_logic_vector(3 downto 0);
signal min1:std_logic_vector(3 downto 0);
signal min2:std_logic_vector(3 downto 0);
signal seth1:std_logic_vector(3 downto 0);
signal seth2:std_logic_vector(3 downto 0);
signal setm1:std_logic_vector(3 downto 0);
signal setm2:std_logic_vector(3 downto 0);
signal sec1:std_logic_vector(3 downto 0);
signal sec2:std_logic_vector(3 downto 0);
signal h1:std_logic_vector(3 downto 0);
signal h2:std_logic_vector(3 downto 0);
signal m1:std_logic_vector(3 downto 0);
signal m2:std_logic_vector(3 downto 0);
signal s1:std_logic_vector(3 downto 0);
signal s2:std_logic_vector(3 downto 0);
signal sph1,sph2,spm1,spm2,sps1,sps2:std_logic_vector(3 downto 0);
signal count_sec:std_logic_vector(9 downto 0);
signal sec_co :std_logic;
signal co1,co2,co3,co4:std_logic; --进位
signal switch :std_logic_vector(1 downto 0); --表示状态
3. 分频模块
用来定义秒count_sec用来计时钟个数,当count_sec=11时,及得到1Hz信号。代码如下: process (clk) is --define a second
begin
if(clk'event and clk='1')then
if(count_sec="11")then
count_sec<="0000000000";
sec_co<='1';
else
count_sec<=count_sec+'1';
sec_co<='0';
end if;
end if;
end process;
4.时钟正常走时模块
该模块使用6个进程实现,分别为秒个位计时、秒十位计时、分个位计时、分十位计时、时个位计时、时十位计时。
process(sec_co) is ------------秒个位
begin
if switch="00" then --正常状态
if sec_co='1' then
if sec2="1001" then
sec2<="0000";
co1<='1';
else
sec2<=sec2+'1';
co1<='0';
end if;
end if;
elsif switch="01" then --调时状态
sec2<="0000";
end if;
end process;
--------------------------------------------------
process (co1) is -------秒十位
begin
if switch="00" then
if co1'event and co1='1' then
if (sec1="0101")then
sec1<="0000";
co2<='1';
else
sec1<=sec1+'1';
co2<='0';
end if;
end if;
elsif switch="01" then
sec1<="0000";
end if;
end process;
-------------------------------------------------
process (co1,co2) is --------分钟个位
begin
if switch="00" then
if co2'event and co2='1' then
if min2="1001" then
min2<="0000";
co3<='1';
else
min2<=min2+'1';
co3<='0';
end if;
end if;
elsif switch="01" then
min2<=setm2;
end if;
end process;
------------------------------------------------------ process (co3) is -----------分钟十位
begin
if switch="00" then
if co3='1' then
if min1="0101" then
min1<="0000";
co4<='1';
else
min1<=min1+'1';
co4<='0';
end if;
end if;
elsif switch="01" then
min1<=setm1;
end if;