可编程逻辑器件数字钟_第1页
可编程逻辑器件数字钟_第2页
可编程逻辑器件数字钟_第3页
可编程逻辑器件数字钟_第4页
可编程逻辑器件数字钟_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、可编程逻辑器件及其应用 一 设计要求用Verilog HDL设计一个多功能数字钟基本功能描述:1. 时钟功能:包括时、分、秒的显示;2. 定时与闹钟功能:能在设定的时间发出闹铃音;3. 校时功能:能非常方便地对小时、分钟和秒进行手动调整以校准时间;4. 整点报时功能:每逢整点,产生“嘀嘀嘀嘀-嘟”,四短一长的报时音。二 仿真环境 用Modelsim进行编译和仿真,工程文件在clocknew1文件夹中。三 结果说明 此次设计实现了数字钟的基本功能,能够进行时分秒的计时,校准,能够整点报时,在设定的时间实现响铃功能。此次设计对各种功能进行了分模块设计,记数模块中,对秒位,分位进行60位记数,小时模

2、块进行24位记数;同时在记数模块中进行校准操作;报时模块里,每逢整点前的59分56秒、59分57秒、59分58秒、59分59秒,和整点时刻,发出“嘀嘀嘀嘀-嘟”的报时声;闹钟模块里,手动对数字钟进行定时,当数字钟的时刻与定时时刻相同时,ring=1发出响铃声。在以上各个功能的模块基础上,设置top顶层模块,将以上功能综合起来实现。为了验证数字钟的功能,编写测试testench模块,输入时钟#5 clk=clk,观察各个信号输出。四 仿真结果图1仿真整体效果图图2当reset键为0时,开始计数图3 秒位计数图4 分钟计数图5 小时位计数图6 整点报时功能图7 定时响铃功能图8 校时功能,校时使能

3、键为1,停止计数,校时图9 校时使能键为0,按校好的时间继续计数五 设计代码/顶层模块module top ( /input clk,reset012,dssl,dssh,dsml,dsmh,dshl,dshh,dingshi, ksec,kmin,khour,cntsec,cntmin,cnthour, /output sl,sh,ml,mh,hl,hh,di,do,ring ); input clk; input reset012; input 3:0 dssl,dssh,dsml,dsmh,dshl,dshh; input ksec,kmin,khour; input 7:0cntsec

4、,cntmin,cnthour; input dingshi; output3:0 sl,sh,ml,mh,hl,hh; wire 3:0 sl,sh,ml,mh,hl,hh; output di,do,ring; wire di,do,ring; wire 3:0 c,d,e,f,g,j; wire a,b; /对模块立化 second my_second (.clk(clk),.reset(reset012),.sh(d),.sl(c),.co(a),.ksec(ksec),.cntsec(cntsec); minute my_minute (.reset1(reset012),.mh(f

5、),.ml(e),.clk1(a),.co1(b),.kmin(kmin),.cntmin(cntmin); hour my_hour (.reset2(reset012),.hh(j),.hl(g),.clk2(b),.khour(khour),.cnthour(cnthour); baoshi my_baoshi (.bssl(c),.bssh(d),.bsml(e),.bsmh(f),.bshl(g),.bshh(j),.di(di),.do(do); naozhong my_naozhong (.dssl(dssl),.dssh(dssh),.dsml(dsml),.dsmh(dsmh

6、),.dshl(dshl),.dshh(dshh), .clksl(c),.clksh(d),.clkml(e),.clkmh(f),.clkhl(g),.clkhh(j),.dingshi(dingshi),.ring(ring); assign sl = c;assign sh = d;assign ml = e;assign mh = f;assign hl = g;assign hh = j;endmodule /秒位计数模块module second(clk,reset,sh,sl,co,ksec,cntsec);input clk; input reset; output3:0sh

7、,sl; / 秒位输出的十位和个位reg3:0sh,sl;output co; /进位reg co;input ksec;input7:0cntsec;reg7:0cnt; /计数器/遇到时钟上升沿或置位下降沿触发always(posedge clk or negedge reset) begin if(ksec=1) begin /校准 cnt=cntsec; end else if(reset=0) begin /复位 sl=4d0;sh=4d0;cnt=0;end else begin /计数到60,进位 if(cnt=8d60) beginsl=4d0;sh=4d0;cnt=8d0;c

8、o=1d1;endelse begin /小于60,继续计数cnt=cnt+1;co=1d0 ;sh=cnt/10; /十位sl=cnt%10; /个位 endendend endmodule/分钟计数模块module minute(reset1,mh,ml,clk1,co1,kmin,cntmin);input reset1; /复位input clk1; /时钟output3:0mh,ml; / 分钟十位和个位reg3:0mh,ml;output co1; /进位reg co1;input kmin;input7:0cntmin;reg7:0cnt1; /计数器/遇到时钟和复位触发alwa

9、ys(negedge clk1 or negedge reset1) begin if(kmin=1) begin /校准 cnt1=cntmin; end else begin if(reset1=0) begin /复位ml=0;mh=0;cnt1=0; end else if(cnt1=8d60) begin /计数到60,进位。重新计数ml=4d0;mh=4d0;cnt1=8d0;co1=1d1;endelse begin /计数不到60继续cnt1=cnt1+1;co1=1d0 ;mh=cnt1/10; /十位ml=cnt1%10; /个位endendend endmodule/小时

10、计数模块module hour(reset2,hh,hl,clk2,khour,cnthour);input clk2; /时钟input reset2; /复位output3:0hh,hl; / ?reg3:0hh,hl;reg7:0cnt2; /计数器input khour;input7:0 cnthour;/遇到时钟和复位触发always(negedge clk2 or negedge reset2) begin if(khour=1) begin /校准 cnt2=cnthour; end else if(reset2=0) begin /复位 hl=0; hh=0; cnt2=0;

11、end else begin /计数到24重新计数 if(cnt2=8d24) begin hl=4d0; hh=4d0; cnt2=8d0; end else begin /计数不到24继续 cnt2=cnt2+1; hh=cnt2/10; /十位 hl=cnt2%10; /个位 end endend endmodule /闹钟模块,在设定的时间响铃module naozhong(dssl,dssh,dsml,dsmh,dshl,dshh, /input clksl,clksh,clkml,clkmh,clkhl,clkhh, /input dingshi,ring);/手动定时input3

12、:0dssl,dssh,dsml,dsmh,dshl,dshh; input3:0clksl,clksh,clkml,clkmh,clkhl,clkhh;reg3:0naosl,naosh,naoml,naomh,naohl,naohh;input dingshi; /定时使能键output ring; /响铃键reg ring;/定时变化触发always(dssl or dssh or dsml or dsmh or dshl or dshh) begin if(dingshi=1) begin naosl=dssl; naosh=dssh; naoml=dsml; naomh=dsmh;

13、naohl=dshl; naohh=dshh; end else begin naosl=naosl; naosh=naosh; naoml=naoml; naomh=naomh; naohl=naohl; naohh=naohh; end end /时钟变化触发,当数字钟时钟与定时时钟相同时响铃; always(clksl or clksh or clkml or clkmh or clkhl or clkhh or naosl or naosh or naoml or naomh or naohl or naohh) begin if(naosl=clksl)&(naosh=clksh)&

14、(naoml=clkml)&(naomh=clkmh) &(naohl=clkhl)&(naohh=clkhh) ring=1d1; else ring=1d0; endendmodule/整点报时模块module baoshi(bssl,bssh,bsml,bsmh,bshl,bshh,di,do); input3:0bssl,bssh,bsml,bsmh,bshl,bshh; output di,do; reg di,do; /在59分56秒 59分57秒 59分58秒 59分59秒发出嘀嘀嘀嘀的声音 always(bssl or bssh or bsml or bsmh or bshl

15、or bshh) begin if( ( bsmh=4d5 ) & ( bsml=4d9 ) & ( bssh=4d5 ) & ( bssl=4d6 ) ) di=1d1; else if( ( bsmh=4d5 ) & ( bsml=4d9 ) & ( bssh=4d5 )& ( bssl=4d7 ) ) di=1d1; else if( (bsmh=4d5 ) & ( bsml=4d9 ) &( bssh=4d5 ) & ( bssl=4d8 ) ) di=1d1; else if( ( bsmh=4d5 ) & ( bsml=4d9 ) & ( bssh=4d5 ) & ( bssl=4

16、d8 ) ) di=1d1; else di=1d0; end /整点发出嘟的声音 always(bssl or bssh or bsml or bsmh or bshl or bshh) begin if(bsmh=4d0)&(bsml=4d0)&(bssh=4d0)&(bssl=4d0) do=1d1; else do=1d0; endendmodule /测试模块timescale 1ns/100psmodule testbench; reg clk; reg reset012; reg dingshi; reg 3:0 dssl,dssh,dsml,dsmh,dshl,dshh; re

17、g 7:0 cntsec,cntmin,cnthour; reg ksec,kmin,khour; wire3:0 sl,sh,ml,mh,hl,hh; wire di,do,ring; initial /set simulate time begin clk=0; reset012=1; dingshi = 0; #100 dingshi = 1; #100 dingshi = 0; #1000 reset012=0; #1000 reset012 = 1; # $stop; end initial begin /when dingshi=1,you can set dingshi; din

18、gshi=1d1; end initial begin cntsec=8d55; ksec=0; # ksec=1; # ksec=0; end initial begin cntmin=8d55; kmin=0; # kmin=1; # kmin=0; end initial begin cnthour=8d0; khour=0; # khour=1; # khour=0; end initial /set dingshi; begin dshh=4d0; dshl=4d0; dsmh=4d0; dsml=4d1; dssh=4d1; dssl=4d0; end initial begin /clock with period 10nsforever #5 clk = clk; end top u1 (.clk(clk),.res

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论