《2022年数字钟的VHDL设计 .pdf》由会员分享,可在线阅读,更多相关《2022年数字钟的VHDL设计 .pdf(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、数字钟的 VHDL 设计一、设计目的1.掌握各类计数器及将它们相连的方法;2.掌握多个数码管动态显示的原理与方法;3.掌握用 FPGA 技术的层次化设计方法;4.进一步掌握用VHDL 硬件描述语言的设计思想;5.了解有关数字系统的设计。二、设计要求基本要求:1、24 小时计数显示;2、具有校时功能(时,分);附加要求:1、实现闹钟功能(定时,闹响);三、源代码library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity szz is port(clk:in std_logic; clk1:i
2、n std_logic; md1:in std_logic; md2:in std_logic_vector(1 downto 0); speak:out std_logic; dout:out std_logic_vector(6 downto 0); selout:out std_logic_vector(2 downto 0); end szz; architecture one of szz is signal sel:std_logic_vector(2 downto 0); signal hou1:std_logic_vector(3 downto 0); signal hou2:
3、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:st
4、d_logic_vector(3 downto 0); signal sec2:std_logic_vector(3 downto 0); signal h1:std_logic_vector(3 downto 0); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - - - - - signal h2:std_logic_vector(3 downto 0); signal m1:std_logic_vector(3 downto 0); si
5、gnal m2:std_logic_vector(3 downto 0); signal s1:std_logic_vector(3 downto 0); signal s2:std_logic_vector(3 downto 0); - begin -模 6 计数choice:process(clk1) begin if clk1event and clk1=1 then if sel=101 then sel=000; else sel=sel+1; end if; end if; end process choice; -小时十位h110:process(clk,hou2,min1,mi
6、n2,sec1,sec2,md1,md2) begin if clkevent and clk=1 then if (hou1=0010 and hou2=0011)and(min1=0101 and min2=1001) and (sec1=0101 and sec2=1001) then hou1=0000; elsif hou1=0010and hou2=0011and md1=0 and md2=01 then-当时间为23 点且处于校时状态时hou1=0000; elsif (hou2=1001and(min1=0101 and min2=1001) and (sec1=0101 a
7、nd sec2=1001)or (hou2=1001and md1=0 and md2=01) then hou1=hou1+1; end if; end if; end process h110; -小时个位h220:process(clk,min1,min2,sec1,sec2,md1,md2,hou1) begin if clkevent and clk=1 then if (hou1=0010 and hou2=0011)and(min1=0101 and min2=1001) and (sec1=0101 and sec2=1001) then hou2=0000; elsif ho
8、u2=1001and(min1=0101 and min2=1001) and (sec1=0101 and sec2=1001) then 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 7 页 - - - - - - - - - hou2=0000; elsif (hou2=1001and md1=0 and md2=01)or (hou1=0010and hou2=0011) then hou2=0000;-md=1; elsif (min1=0101 and mi
9、n2=1001) and (sec1=0101 and sec2=1001)or (md1=0 and md2=01) then hou2=hou2+1;-speak=clk; end if; end if; end process h220; -分钟十位m110:process(clk,min2,sec1,sec2,md1,md2) begin if clkevent and clk=1 then if (min1=0101 and min2=1001) and (sec1=0101 and sec2=1001) then min1=0000; elsif min1=0101and min2
10、=1001and (md1=0 and md2=00)then min1=0000; elsif (min2=1001and (sec1=0101 and sec2=1001) or (min2=1001and md1=0 and md2=00)then min1=min1+1; end if; end if;-end if; end process m110; -分钟个位m220:process(clk,sec1,sec2,md1,md2) begin if clkevent and clk=1 then if min2=1001and (sec1=0101 and sec2=1001)th
11、en min2=0000; elsif min2=1001and (md1=0 and md2=00)then min2=0000; else if (sec1=0101 and sec2=1001) or(md1=0 and md2=00)then min2=min2+1; end if; end if;end if; end process m220; -秒十位s110:process(clk) begin if clkevent and clk=1 then if (sec1=0101 and sec2=1001)then sec1=0000; else if sec2=1001then
12、 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 7 页 - - - - - - - - - sec1=sec1+1; end if; end if;end if; end process s110; -秒个位s220:process(clk) begin if clkevent and clk=1 then if sec2=1001 then sec2=0000; else sec2=sec2+1; end if; end if; end process s220; -
13、时间设置小时部分sethour1:process(clk,seth2)beginif clkevent and clk=1 thenif seth1=0010and seth2=0011 thenseth1=0000;elsif seth2=1001 thenseth1=seth1+1;end if;end if;end process sethour1;-sethour2:process(clk,md1,md2,seth1)beginif clkevent and clk=1 thenif (seth1=0010and seth2=0011)or seth2=1001thenseth2=00
14、00;elsif md1=1 and md2=00 thenseth2=seth2+1;end if;end if;end process sethour2;-时间设置分钟部分setmin1:process(clk,setm2)beginif clkevent and clk=1 thenif setm1=0101and setm2=1001thensetm1=0000;elsif setm2=1001thensetm1=setm1+1;名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第
15、 4 页,共 7 页 - - - - - - - - - end if;end if;end process setmin1;-setmin2:process(clk,md1,md2)beginif clkevent and clk=1thenif setm2=1001thensetm2=0000;elsif md1=1 and md2=01thensetm2=setm2+1;end if;end if;end process setmin2;-闹铃speaker:process(clk1,hou1,hou2,min1,min2)beginif clk1event and clk1=1then
16、if seth1=hou1 and seth2=hou2 and setm1=min1 and setm2=min2 thenspeak=clk1;else speak=0;end if;end if;end process speaker;-disp:process(sel,md1,hou1,hou2,min1,min2,sec1,sec2,seth1,seth2,setm1,setm2)beginif sel=000 thenseloutdoutdoutdoutdout=1000000;end case;elsif sel=001 thenseloutdoutdoutdoutdoutdou
17、tdoutdoutdoutdoutdoutdout=1000000;end case;elsif sel=010 thenseloutdoutdoutdoutdoutdoutdoutdout=1000000;end case;elsif sel=011 thenseloutdoutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=1000000;end case;elsif sel=100 thenseloutdoutdoutdoutdoutdoutdoutdout=1000000;end case;elsif sel=101 thenseloutdoutdou
18、tdoutdoutdoutdoutdoutdoutdoutdoutdout=1000000;end case;end if;if md1=0 then- 计时时间显示和设置模式h1=hou1;h2=hou2;m1=min1;m2=min2;s1=sec1;s2=sec2;else - 闹铃时间现实和设置模式h1=seth1;h2=seth2;m1=setm1;m2=setm2;s1=1111;s2=1111;end if;end process disp;-end one;名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 7 页 - - - - - - - - -