VHDL设计数字钟系统.doc

上传人:仙人指路1688 文档编号:4146806 上传时间:2023-04-07 格式:DOC 页数:14 大小:44.50KB
返回 下载 相关 举报
VHDL设计数字钟系统.doc_第1页
第1页 / 共14页
VHDL设计数字钟系统.doc_第2页
第2页 / 共14页
VHDL设计数字钟系统.doc_第3页
第3页 / 共14页
VHDL设计数字钟系统.doc_第4页
第4页 / 共14页
VHDL设计数字钟系统.doc_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《VHDL设计数字钟系统.doc》由会员分享,可在线阅读,更多相关《VHDL设计数字钟系统.doc(14页珍藏版)》请在三一办公上搜索。

1、VHDL设计数字钟系统1熟练利用VHDL语言进行数字系统设计; 2. 掌握数字系统的设计方法自顶向下的设计思想; 3掌握计数器的设计与使用; 4掌握调时,调分功能的实现;5根据数字钟的功能要求设计一个数字钟;6. 掌握闹钟系统的原理。 数字钟是一计时的工具,有着广泛的用途。本实验的数字钟要求有三个功能按钮:一个是清零按钮reset11,当按下此按钮时,数字钟显示有位都清零二是调分钟的按钮 setmin,当按下此按钮时分钟会以1HZ的频率速度进行调时,而且在调分钟时秒钟会暂停不动;三是调小时的按钮sethour,当按下此按钮时时钟会以1HZ的频率速度进行调时,在调小时时分钟会暂停不动,但秒钟是正

2、常记时的。 另外还有一个闹钟模块,在闹钟模块中,当按下调时或调分键时,数码显示管显示所调闹钟的时间,并进行调时或调分。当两个键都未按下时,数码管显示数字钟的时间。当设定的闹钟时间和数字钟的时间一致时,红灯亮,黄灯灭,同时喇叭叫。其余时间黄灯亮,红灯灭,喇叭不叫。此数字钟是以24小时制记时,当到整点时会报时一分钟,按下清零键时也会报时一分钟。主要元件有计数器,分频器,报时器,选择器和译码器等。控制逻辑主要是用来实现计数和清零。基本方框图如下:.分频模块采用原理图输入方式实现2分频与1000分频,但这里并没有用到1000分频,因为后来考虑到精度问题,将千分频用直接输入了。程序如图:利用三个7490

3、进行硬件分频!微秒模块采用VHDL语言输入方式,以时钟clk,清零信号clr以及暂停信号STOP为进程敏感变量,程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity MINSECONDb isport(clk,clrm,stop:in std_logic;-时钟/清零信号 secm1,secm0:out std_logic_vector(3 downto 0);-秒高位/低位 co:out std_logic);-输出/进位信号end MINSECONDb;architectur

4、e SEC of MINSECONDb issignal clk1,DOUT2:std_logic;beginprocess(clk,clrm)variable cnt1,cnt0:std_logic_vector(3 downto 0);-计数 VARIABLE COUNT2 :INTEGER RANGE 0 TO 10 ;beginIF CLKEVENT AND CLK=1THEN IF COUNT2=0 AND COUNT210 THEN COUNT2:=COUNT2+1; ELSE COUNT2:=0; DOUT2= NOT DOUT2; END IF; END IF;if clrm=

5、1 then-当clr为1时,高低位均为0cnt1:=0000;cnt0:=0000;elsif clkevent and clk=1 then if stop=1 then cnt0:=cnt0; cnt1:=cnt1; end if;if cnt1=1001 and cnt0=1000 then-当记数为98(实际是经过59个记时脉冲)co=1;-进位cnt0:=1001;-低位为9elsif cnt01001 then-小于9时cnt0:=cnt0+1;-计数-elsif cnt0=1001 then-clk1=not clk1;elsecnt0:=0000;if cnt11001 th

6、en-高位小于9时cnt1:=cnt1+1;elsecnt1:=0000;co=0;end if;end if;end if;secm1=cnt1;secm0=cnt0;end process;end SEC;秒模块程序清单 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity SECOND isport(clk,clr:in std_logic;-时钟/清零信号 sec1,sec0:out std_logic_vector(3 downto 0);-秒高位/低位 co:out std_l

7、ogic);-输出/进位信号end SECOND;architecture SEC of SECOND isbeginprocess(clk,clr)variable cnt1,cnt0:std_logic_vector(3 downto 0);-计数beginif clr=1 then-当ckr为1时,高低位均为0cnt1:=0000;cnt0:=0000;elsif clkevent and clk=1 thenif cnt1=0101 and cnt0=1000 then-当记数为58(实际是经过59个记时脉冲)co=1;-进位cnt0:=1001;-低位为9elsif cnt01001

8、 then-小于9时cnt0:=cnt0+1;-计数elsecnt0:=0000;if cnt10101 then-高位小于5时cnt1:=cnt1+1;elsecnt1:=0000;co=0;end if;end if;end if;sec1=cnt1;sec0=cnt0;end process;end SEC; 分模块程序清单 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity MINUTE isport(clk,en:in std_logic; min1,min0:out std_

9、logic_vector(3 downto 0); co:out std_logic);end MINUTE;architecture MIN of MINUTE isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);beginif clkevent and clk=1 thenif en=1 thenif cnt1=0101 and cnt0=1000 thenco=1;cnt0:=1001;elsif cnt01001 thencnt0:=cnt0+1;elsecnt0:=0000;if cnt10101 th

10、encnt1:=cnt1+1;elsecnt1:=0000;co=0;end if;end if;end if;end if;min1=cnt1;min0=cnt0;end process;end MIN;时模块程序清单 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity HOUR isport(clk,en:in std_logic;-输入时钟/高电平有效的使能信号 h1,h0:out std_logic_vector(3 downto 0);-时高位/低位end HOUR;archi

11、tecture hour_arc of HOUR isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);-记数beginif clkevent and clk=1 then-上升沿触发if en=1 then-同时“使能”为1if cnt1=0010 and cnt0=0011 thencnt1:=0000;-高位/低位同时为0时cnt0:=0000;elsif cnt01001 then-低位小于9时,低位记数累加cnt0:=cnt0+1;elsecnt0:=0000;cnt1:=cnt1+1;-高位记数累加en

12、d if;end if;end if;h1=cnt1;h0=cnt0;end process;end hour_arc;动态扫描模块 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity SELTIME is port( clk:in std_logic;-扫描时钟 secm1,secm0,sec1,sec0,min1,min0,h1,h0:in std_logic_vector(3 downto 0);-分别为秒个位/时位;分个位

13、/ 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);-计数信号begin sel=111) then count=000; else countdaoutdaoutdaoutdaoutdaoutdaoutdaoutdaout=h1; end case; end process;end fun;报时模块 li

14、brary ieee;use ieee.std_logic_1164.all;entity ALERT isport(m1,m0,s1,s0:in std_logic_vector(3 downto 0);-输入秒、分高/低位信号 clk:in std_logic;-高频声控制 q500,qlk:out std_logic);-低频声控制end ALERT;architecture sss_arc of ALERT is begin process(clk) begin if clkevent and clk=1 then if m1=0101 and m0=1001 and s1=0101

15、then-当秒高位为5,低位为9时且分高位为5 if s0=0001 or s0=0011 or s0=0101 or s0=0111 then-当分的低位为1或3或5或7时 q500=1;-低频输出为1 else q500=0;-否则输出为0 end if; end if;if m1=0101 and m0=1001 and s1=0101 and s0=1001 then-当秒高位为5,低位为9时且分高位为5,-分低位为9时,也就是“59分59秒”的时候“报时” qlk=1;-高频输出为1 else qlkqqqqqqqqqq=1101111;-显示9end case; end proce

16、ss;end disp_are;顶层文件(原理图输入) * 数字钟设计模块与程序(不含秒表)* 1.分频模块(原理图输入) 2. 秒模块程序 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity SECOND isport(clk,clr:in std_logic; sec1,sec0:out std_logic_vector(3 downto 0); co:out std_logic);end SECOND;architecture SEC of SECOND isbeginproces

17、s(clk,clr)variable cnt1,cnt0:std_logic_vector(3 downto 0);beginif clr=1 thencnt1:=0000;cnt0:=0000;elsif clkevent and clk=1 thenif cnt1=0101 and cnt0=1000 thenco=1;cnt0:=1001;elsif cnt01001 thencnt0:=cnt0+1;elsecnt0:=0000;if cnt10101 thencnt1:=cnt1+1;elsecnt1:=0000;co=0;end if;end if;end if;sec1=cnt1

18、;sec0=cnt0;end process;end SEC;3.分模块程序 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity MINUTE isport(clk,en:in std_logic; min1,min0:out std_logic_vector(3 downto 0); co:out std_logic);end MINUTE;architecture MIN of MINUTE isbeginprocess(clk)variable cnt1,cnt0:std_logi

19、c_vector(3 downto 0);beginif clkevent and clk=1 thenif en=1 thenif cnt1=0101 and cnt0=1000 thenco=1;cnt0:=1001;elsif cnt01001 thencnt0:=cnt0+1;elsecnt0:=0000;if cnt10101 thencnt1:=cnt1+1;elsecnt1:=0000;co=0;end if;end if;end if;end if;min1=cnt1;min0=cnt0;end process;end MIN;4.时模块程序library ieee;use i

20、eee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity HOUR isport(clk,en:in std_logic; h1,h0:out std_logic_vector(3 downto 0);end HOUR;architecture hour_arc of HOUR isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);beginif clkevent and clk=1 thenif en=1 thenif cnt1=0010 and

21、cnt0=0011 thencnt1:=0000;cnt0:=0000;elsif cnt01001 thencnt0:=cnt0+1;end if;end if;end if;h1=cnt1;h0=cnt0;end process;end hour_arc;5.扫描模块程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity SELTIME is port( clk:in std_logic; sec1,sec0,min1,min

22、0,h1,h0:in std_logic_vector(3 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);begin sel=101) then count=000; else countdaoutdaoutdaoutdaoutdaoutdaoutqqqqqqqqqq=1101111;end cas

23、e; end process;end disp_are;7.定时闹钟模块程序 library ieee;use ieee.std_logic_1164.all;entity ALERT isport(m1,m0,s1,s0:in std_logic_vector(3 downto 0); clk:in std_logic; q500,qlk:out std_logic);end ALERT;architecture sss_arc of ALERT is begin process(clk) begin if clkevent and clk=1 then if m1=0101 and m0=1001 and s1=0101 then if s0=0001 or s0=0011 or s0=0101 or s0=0111 then q500=1; else q500=0; end if; end if;if m1=0101 and m0=1001 and s1=0101 and s0=1001 thenqlk=1;elseqlk=0;end if;end if;end process;end sss_arc;参考资料: 2| 评论

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号