基于QuartusⅡ的VHDL语言多功能数字钟.docx
《基于QuartusⅡ的VHDL语言多功能数字钟.docx》由会员分享,可在线阅读,更多相关《基于QuartusⅡ的VHDL语言多功能数字钟.docx(11页珍藏版)》请在冰豆网上搜索。
![基于QuartusⅡ的VHDL语言多功能数字钟.docx](https://file1.bdocx.com/fileroot1/2023-1/23/f651d1f6-9b94-4baf-a731-2e938ab6775c/f651d1f6-9b94-4baf-a731-2e938ab6775c1.gif)
基于QuartusⅡ的VHDL语言多功能数字钟
基于QuartusⅡ的VHDL语言多功能数字钟
注:
任何人不得作为商业用途
数字钟的功能
1)以24小时制显示时、分、秒计数;
2)时间清零,时设置,分设置功能;
3)整点报时功能。
实验环境
1.软件环境:
QuartusII7.2
2.硬件环境:
MAXII-EPM240T100C5
1.分频器
1KHz分频器VHDL:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityFPQ1Kis
port(clk:
instd_logic;
q1khz:
outstd_logic);
end;
architecturebehavofFPQ1Kis
begin
s1:
process(clk)
variablecount2:
integerrange0to50000;
begin
if(clk='1'andclk'event)thencount2:
=count2+1;
if(count2=25000)thenq1khz<='1';
elsif(count2=50000)thenq1khz<='0';
count2:
=0;
endif;
endif;
endprocess;
ENDbehav;
1KHz分频器顶层设计原理图
1Hz分频器VHDL:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityFPQ1is
port(clk:
instd_logic;
q1hz:
outstd_logic);
end;
architecturebehavofFPQ1is
begin
s1:
process(clk)
variablecount2:
integerrange0to1000;
begin
if(clk='1'andclk'event)thencount2:
=count2+1;
if(count2=500)thenq1hz<='1';
elsif(count2=1000)thenq1hz<='0';
count2:
=0;
endif;
endif;
endprocess;
ENDbehav;
1Hz分频器顶层设计原理图
2.秒模块设计
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitySecis
port(clk,reset,min_set:
instd_logic;--clk为1Hz的秒脉冲输入信号,reset为秒清零(复位)信号
--min_set为分钟调整
enmin:
outstd_logic;--enmin为秒模块进位输出
daout:
outstd_logic_vector(6downto0));--2n-1≥60,n=7,27=64,分钟用7位二进制数表示
--daout(6..4)为十位,daout(3..0)为个位,60循环计数
endentitySec;
architecturebehaveofSecis
signalcount:
std_logic_vector(6downto0);--定义内部计数节点,60循环计数
signalenmin1,enmin2:
std_logic;
--enmin为60秒产生的进位,enmin2为调分键产生的向分模块的进位
begin
daout<=count;
enmin2<=(min_setandclk);
enmin<=(enmin1orenmin2);--60秒钟到和调分键均向分模块产生进位脉冲
process(clk,reset,min_set)
begin
if(reset='0')thencount<="0000000";--检测秒模块的1Hz脉冲上升沿
elsif(clk'eventandclk='1')then
if(count(3downto0)="1001")then--秒的个位是否到“9”
ifcount(6downto4)="101"then--秒各位到“9”后,十位计数到“5”
enmin1<='1';
--秒模块的60秒进位输出enmin置“1”,向分模块产生进位
count<="0000000";--秒计数值“0000000”(零秒)
else
count<=count+7;
--秒各位到“9”后,十位计数没到“5”,则加“7”变为“0”,同时向十位进位
endif;
else
count<=count+1;--秒个位没计到“9”时,秒计数值加“1”
enmin1<='0';--秒模块的60秒进位输出enmin1置“0”,不向分模块进位
endif;
endif;
endprocess;
endbehave;
秒模块顶层设计原理图
3.分模块设计
LIBRARYieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
ENTITYMinIS
PORT(clk,clk1,hour_set,reset:
INSTD_LOGIC;--clk为分钟模块的脉冲输入信号,接秒模块的进位输出
--clk1接秒脉冲输入,hour_set为小时调整
enhour:
OUTSTD_LOGIC;--enhour为分钟模块的进位输出
daout:
OUTSTD_LOGIC_VECTOR(6DOWNTO0));
--2n-1≥60,n=7,27=64,分钟用7位二进制数表示
--daout(6..4)为十位,daout(3..0),60循环计数
ENDENTITYMin;
ARCHITECTUREbehaveOFMinIS
SIGNALcount:
STD_LOGIC_VECTOR(6DOWNTO0);--定义内部计数节点,60循环计数
SIGNALenhour1,enhour2:
STD_LOGIC;
--enhour1为60分钟产生的进位。
enhour2为调时键的脉冲
BEGIN
daout<=count;
enhour2<=(hour_setandclk1);
enhour<=(enhour1orenhour2);--60分钟到和调时键均向小时模块产生进位脉冲
PROCESS(clk,reset)
BEGIN
IF(reset='0')THENcount<="0000000";
ELSIF(clk'eventandclk='1')THEN--检测分钟模块的脉冲上升沿
IF(count(3downto0)="1001")THEN--分钟的各位是否到“9”
IFcount(6downto4)="101"THEN--分钟各位到“9”后,十位计数到“5”
enhour1<='1';
--分钟模块的60分钟进位输出enhour1置“1”,向时模块产生进位
count<="0000000";--分钟计数值回零“0000000”(零分)
ELSE
count<=count+7;
--分钟各位到“9”后,十位计数没到“5”,则“7”变为“0”,同时向十位进位
ENDIF;
ELSE
count<=count+1;--分钟各位没计到“9”时,分钟计数值加“1”
enhour1<='0';--分钟模块的60分钟进位输出enhour1置“0”,不向时模块进位
ENDIF;
ENDIF;
ENDPROCESS;
ENDbehave;
分模块顶层设计原理图
4.时模块设计
LIBRARYieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
ENTITYFenIS
PORT(clk,clk1,hour_set,reset:
INSTD_LOGIC;--clk为分钟模块的脉冲输入信号,接秒模块的进位输出
--clk1接秒脉冲输入,hour_set为小时调整
enhour:
OUTSTD_LOGIC;--enhour为分钟模块的进位输出
daout:
OUTSTD_LOGIC_VECTOR(6DOWNTO0));
--2n-1≥60,n=7,27=64,分钟用7位二进制数表示
--daout(6..4)为十位,daout(3..0),60循环计数
ENDENTITYFen;
ARCHITECTUREbehaveOFFenIS
SIGNALcount:
STD_LOGIC_VECTOR(6DOWNTO0);--定义内部计数节点,60循环计数
SIGNALenhour1,enhour2:
STD_LOGIC;
--enhour1为60分钟产生的进位。
enhour2为调时键的脉冲
BEGIN
daout<=count;
enhour2<=(hour_setandclk1);
enhour<=(enhour1orenhour2);--60分钟到和调时键均向小时模块产生进位脉冲
PROCESS(clk,reset)
BEGIN
IF(reset='0')THENcount<="0000000";
ELSIF(clk'eventandclk='1')THEN--检测分钟模块的脉冲上升沿
IF(count(3downto0)="1001")THEN--分钟的各位是否到“9”
IFcount(6downto4)="101"THEN--分钟各位到“9”后,十位计数到“5”
enhour1<='1';
--分钟模块的60分钟进位输出enhour1置“1”,向时模块产生进位
count<="0000000";--分钟计数值回零“0000000”(零分)
ELSE
count<=count+7;
--分钟各位到“9”后,十位计数没到“5”,则“7”变为“0”,同时向十位进位
ENDIF;
ELSE
count<=count+1;--分钟各位没计到“9”时,分钟计数值加“1”
enhour1<='0';--分钟模块的60分钟进位输出enhour1置“0”,不向时模块进位
ENDIF;
ENDIF;
ENDPROCESS;
ENDbehave;
时模块顶层设计原理图
5.整点报时模块
LIBRARYieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityZDBSis
port(clk:
instd_logic;--脉冲输入,可接1Hz秒脉冲输入,用于整点声报时发出间断报时响声
daout:
instd_logic_vector(6downto0);
dain:
instd_logic_vector(6downto0);--分钟模块计数输入
speak:
outstd_logic);
endentityZDBS;
architecturebehaveofZDBSis
begin
process(dain,clk)
begin
ifdaout<="0000000"anddain<="0000000"then--“0000000”(“零分”)时,即为整点
speak<=clk;
elsespeak<='1';
endif;
endprocess;
endbehave;
整点报时模块顶层设计原理图
6.动态显示模块
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
useieee.std_logic_arith.all;
entityDTXSis
port(clk1:
instd_logic;--动态扫描输入脉冲
sec,min:
instd_logic_vector(6downto0);--7位二进制数表示的秒、分计数输入
hour:
instd_logic_vector(5downto0);--6位二进制数表示的小时计数输入
daout:
outstd_logic_vector(3downto0);--4位十进制码计数输入
dp:
outstd_logic;--时、分、秒间的间隔“点”输出
sel:
outstd_logic_vector(2downto0));
--3位数码管位选输出,接外部3-8译码器输出,译码输出再经驱动接数码管共阴极端
endentityDTXS;
architecturebehaveofDTXSis
signalcount:
std_logic_vector(2downto0);
--定义内部计数节点,六进制循环计数(6个数码管显示)
begin
sel<=count;
process(clk1)
begin
if(clk1'eventandclk1='1')then--检测动态扫描输入脉冲上升沿
if(count>="101")thencount<="000";
elsecount<=count+1;--“000~101”六进制循环计数
endif;
endif;
casecountis
when"000"=>daout<=sec(3downto0);dp<='0';
--“000”时选择“秒的各位”计数值显示,点不亮
when"001"=>daout(3)<='0';daout(2downto0)<=sec(6downto4);dp<='0';
--“001”时选择“秒的各位”计数值显示,点不亮
when"010"=>daout<=min(3downto0);dp<='1';
--“010”时选择“分的各位”计数值显示,点亮
when"011"=>daout(3)<='0';daout(2downto0)<=min(6downto4);dp<='0';
--“011”时选择“分的各位”计数值显示,点不亮
when"100"=>daout<=hour(3downto0);dp<='1';
--“100”时选择“时的各位”计数值显示,点亮
whenothers=>daout(3downto2)<="00";
daout(1downto0)<=hour(5downto4);dp<='0';
--“101”时选择“时的各位”计数值显示,点不亮
endcase;
endprocess;
endbehave;
动态显示模块顶层设计原理图
7.显示译码模块
显示译码模块顶层设计原理图
8.总顶层电路
总顶层电路设计原理图
总结
在此次的数字钟设计过程中,最终结果与预期效果基本一致更进一步地了解和熟悉有关数字电路的知识和具体的应用。
学会了利用QuartusⅡ硬件描述语言VHDL编写程序。
并能根据仿真结果分析设计的存在的问题和缺陷,从而进行程序的调试和完善。
此次的数字钟设计重点在于报时模块的代码编写。
通过这次的设计实验更进一步地增强了实验的动手能力,对数字钟的工作与原理有了更加透彻的理解。