1、基于Quartus的VHDL语言多功能数字钟基于Quartus的VHDL语言多功能数字钟注:任何人不得作为商业用途数字钟的功能1)以24小时制显示时、分、秒计数; 2)时间清零,时设置,分设置功能;3)整点报时功能。实验环境1.软件环境:QuartusII 7.22.硬件环境:MAXII-EPM240T100C51.分频器1KHz分频器VHDL:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity FPQ1K is port(clk :in std_logic; q1khz :out st
2、d_logic);end ;architecture behav of FPQ1K is begins1:process(clk)variable count2: integer range 0 to 50000;begin if (clk=1and clkevent)then count2:=count2+1;if (count2=25000) then q1khz=1; elsif (count2=50000) then q1khz=0; count2:=0; end if; end if;end process;END behav;1KHz分频器顶层设计原理图1Hz分频器VHDL:lib
3、rary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity FPQ1 is port(clk :in std_logic; q1hz :out std_logic);end ;architecture behav of FPQ1 is begins1:process(clk)variable count2: integer range 0 to 1000;begin if (clk=1and clkevent)then count2:=count2+1;if (count2=500) then q1h
4、z=1; elsif (count2=1000) then q1hz=0; count2:=0; end if; end if;end process;END behav;1Hz分频器顶层设计原理图2.秒模块设计library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all; entity Sec isport(clk,reset,min_set:in std_logic;-clk为1Hz的秒脉冲输入信号,reset为秒清零(复位)信号 -min_set为分钟调整 enmin:out std_logic; -en
5、min为秒模块进位输出 daout:out std_logic_vector(6 downto 0); -2n-160,n=7,27=64,分钟用7位二进制数表示 -daout(6.4)为十位,daout(3.0)为个位,60循环计数end entity Sec;architecture behave of Sec is signal count:std_logic_vector(6 downto 0); -定义内部计数节点,60循环计数 signal enmin1,enmin2:std_logic; -enmin为60秒产生的进位,enmin2为调分键产生的向分模块的进位begindaout
6、=count; enmin2=(min_set and clk); enmin=(enmin1 or enmin2); -60秒钟到和调分键均向分模块产生进位脉冲process(clk,reset,min_set)begin if(reset=0)then count=0000000; -检测秒模块的1Hz脉冲上升沿 elsif(clkevent and clk=1)then if(count(3 downto 0)=1001)then -秒的个位是否到“9” if count(6 downto 4)=101then -秒各位到“9”后,十位计数到“5” enmin1=1; -秒模块的60秒进
7、位输出enmin置“1”,向分模块产生进位 count=0000000; -秒计数值“0000000”(零秒) else count=count+7; -秒各位到“9”后,十位计数没到“5”,则加“7”变为“0”,同时向十位进位 end if; else count=count+1; -秒个位没计到“9”时,秒计数值加“1” enmin1=0; -秒模块的60秒进位输出enmin1置“0”,不向分模块进位 end if; end if;end process;end behave; 秒模块顶层设计原理图3.分模块设计LIBRARY ieee;use ieee.std_logic_1164.al
8、l;use ieee.std_logic_unsigned.all;ENTITY Min ISPORT(clk,clk1,hour_set,reset:IN STD_LOGIC; -clk为分钟模块的脉冲输入信号,接秒模块的进位输出 -clk1接秒脉冲输入,hour_set为小时调整 enhour:OUT STD_LOGIC; -enhour为分钟模块的进位输出 daout:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);-2n-160,n=7,27=64,分钟用7位二进制数表示 -daout(6.4)为十位,daout(3.0),60循环计数END ENTITY Min;A
9、RCHITECTURE behave OF Min ISSIGNAL count:STD_LOGIC_VECTOR(6 DOWNTO 0);-定义内部计数节点,60循环计数SIGNAL enhour1,enhour2:STD_LOGIC;-enhour1为60分钟产生的进位。enhour2为调时键的脉冲BEGIN daout= count; enhour2=(hour_set and clk1); enhour=(enhour1 or enhour2); -60分钟到和调时键均向小时模块产生进位脉冲PROCESS(clk,reset)BEGINIF(reset=0)THEN count=000
10、0000; ELSIF(clkevent and clk=1)THEN -检测分钟模块的脉冲上升沿 IF(count(3 downto 0)=1001)THEN -分钟的各位是否到“9” IF count(6 downto 4)=101THEN -分钟各位到“9”后,十位计数到“5” enhour1=1; -分钟模块的60分钟进位输出enhour1置“1”,向时模块产生进位 count=0000000; -分钟计数值回零“0000000”(零分) ELSE count=count+7; -分钟各位到“9”后,十位计数没到“5”,则“7”变为“0”,同时向十位进位 END IF; ELSE co
11、unt=count+1; -分钟各位没计到“9”时,分钟计数值加“1” enhour1=0; -分钟模块的60分钟进位输出enhour1置“0”,不向时模块进位 END IF; END IF;END PROCESS;END behave;分模块顶层设计原理图4.时模块设计LIBRARY ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ENTITY Fen ISPORT(clk,clk1,hour_set,reset:IN STD_LOGIC; -clk为分钟模块的脉冲输入信号,接秒模块的进位输出 -clk1接秒脉
12、冲输入,hour_set为小时调整 enhour:OUT STD_LOGIC; -enhour为分钟模块的进位输出 daout:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);-2n-160,n=7,27=64,分钟用7位二进制数表示 -daout(6.4)为十位,daout(3.0),60循环计数END ENTITY Fen;ARCHITECTURE behave OF Fen ISSIGNAL count:STD_LOGIC_VECTOR(6 DOWNTO 0);-定义内部计数节点,60循环计数SIGNAL enhour1,enhour2:STD_LOGIC;-enhou
13、r1为60分钟产生的进位。enhour2为调时键的脉冲BEGIN daout= count; enhour2=(hour_set and clk1); enhour=(enhour1 or enhour2); -60分钟到和调时键均向小时模块产生进位脉冲PROCESS(clk,reset)BEGINIF(reset=0)THEN count=0000000; ELSIF(clkevent and clk=1)THEN -检测分钟模块的脉冲上升沿 IF(count(3 downto 0)=1001)THEN -分钟的各位是否到“9” IF count(6 downto 4)=101THEN -分
14、钟各位到“9”后,十位计数到“5” enhour1=1; -分钟模块的60分钟进位输出enhour1置“1”,向时模块产生进位 count=0000000; -分钟计数值回零“0000000”(零分) ELSE count=count+7; -分钟各位到“9”后,十位计数没到“5”,则“7”变为“0”,同时向十位进位 END IF; ELSE count=count+1; -分钟各位没计到“9”时,分钟计数值加“1” enhour1=0; -分钟模块的60分钟进位输出enhour1置“0”,不向时模块进位 END IF; END IF;END PROCESS;END behave;时模块顶层设
15、计原理图5.整点报时模块LIBRARY ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity ZDBS isport(clk:in std_logic; -脉冲输入,可接1Hz秒脉冲输入,用于整点声报时发出间断报时响声daout:in std_logic_vector(6 downto 0);dain:in std_logic_vector(6 downto 0); -分钟模块计数输入speak:out std_logic);end entity ZDBS;architecture behave of Z
16、DBS isbeginprocess(dain,clk)beginif daout=0000000 and dain=0000000then -“0000000”(“零分”)时,即为整点speak=clk;else speak=1;end if;end process;end behave;整点报时模块顶层设计原理图6.动态显示模块library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity DTXS isport(clk1:in std_
17、logic; -动态扫描输入脉冲 sec,min:in std_logic_vector(6 downto 0); -7位二进制数表示的秒、分计数输入 hour:in std_logic_vector(5 downto 0); -6位二进制数表示的小时计数输入 daout:out std_logic_vector(3 downto 0); -4位十进制码计数输入 dp:out std_logic; -时、分、秒间的间隔“点”输出 sel:out std_logic_vector(2 downto 0); -3位数码管位选输出,接外部3-8译码器输出,译码输出再经驱动接数码管共阴极端end en
18、tity DTXS;architecture behave of DTXS issignal count:std_logic_vector(2 downto 0); -定义内部计数节点,六进制循环计数(6个数码管显示)beginsel=101)then count=000; else countdaout=sec(3 downto 0);dpdaout(3)=0;daout(2 downto 0)=sec(6 downto 4);dpdaout=min(3 downto 0);dpdaout(3)=0;daout(2 downto 0)=min(6 downto 4);dpdaout=hour
19、(3 downto 0);dpdaout(3 downto 2)=00; daout(1 downto 0)=hour(5 downto 4);dp=0;-“101”时选择“时的各位”计数值显示,点不亮 end case;end process;end behave;动态显示模块顶层设计原理图7.显示译码模块显示译码模块顶层设计原理图8.总顶层电路总顶层电路设计原理图总结在此次的数字钟设计过程中,最终结果与预期效果基本一致更进一步地了解和熟悉有关数字电路的知识和具体的应用。学会了利用Quartus硬件描述语言VHDL编写程序。并能根据仿真结果分析设计的存在的问题和缺陷,从而进行程序的调试和完善。此次的数字钟设计重点在于报时模块的代码编写。通过这次的设计实验更进一步地增强了实验的动手能力,对数字钟的工作与原理有了更加透彻的理解。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1