ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:27.73KB ,
资源ID:6038627      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6038627.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(verilog数字钟设计FPGA.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

verilog数字钟设计FPGA.docx

1、verilog数字钟设计FPGA一、课程设计目标 1. 熟悉并掌握verilog 硬件描述语言 2. 熟悉quartus 软件开发环境 3. 学会设计大中规模的数字电路,并领会其中的设计思想 二、课程设计实现的功能 (1)设计一个数码管实时显示时、分、秒的数字时钟(24小时显示模式); (2)可以调节小时,分钟。 (3)能够进行24小时和12小时的显示切换。 (4)可以设置任意时刻闹钟,并且有开关闹钟功能。 (5)有整点报时功能,几点钟LED灯闪亮几下。 (6)有复位按键,复位后时间从零开始计时,但闹钟设置时间不变。 三、设计原理:1、总原理框图: 模显示译码 是 计数 模块 是 附全部代码:

2、 总模块: module clock(clk,reset,MODE,Alarm_ctr,BT2,H12_24,DSH,DSL,DMH,DML,DHH,DHL,dian,bao_signal,nao_signal); input clk;/50MHz input reset,MODE,Alarm_ctr,BT2,H12_24;/复位键,模式选择按钮,闹钟开关档,调节按 钮 ,1224小时切换档 output 7:0DMH,DML,DHH,DHL; /4个数码管显示输入信号 output dian,bao_signal,nao_signal; /时分间隔点,报时信号,闹钟信号 output 3:0

3、DSH,DSL; /秒钟输出信号 wire 3:0 SH,SL,MH,ML,HH,HL; wire 3:0 LED_mode; wire 3:0 HH12,HL12,HH24,HL24,MH24,ML24,SH24,SL24; wire 3:0 set_HH,set_HL,set_MH,set_ML; wire _1HZ,_10ms,_250ms,_500ms; wire Keydone1; wire Keydone2; wire co1,co11,co111,co2,co22,co222,set_co2; wire 3:0mode_flag; assign dian=1b0; devide_

4、f u1(_1HZ,_10ms,_250ms,_500ms,reset,clk); /分频,得到4种不同频率的时钟信号 key_press u2(_10ms,MODE,Keydone1); /模式档按钮去抖动 key_press u20(_10ms,BT2,Keydone2); /调节按钮去除抖动 mode u3(Keydone1,mode_flag); /通过模式按钮产生不同模式 second u4(_1HZ,reset,mode_flag,Keydone2,SH24,SL24,co1); /秒计时 minute u5(co11,reset,MH24,ML24,co2); /分计时 hour

5、 u6(co22,reset,HH24,HL24); /小时计时 SEG7_LUT u7(DML,ML); /4个数码管显示 SEG7_LUT u8(DMH,MH); SEG7_LUT u9(DHL,HL); SEG7_LUT u10(DHH,HH); display_LED u11(DSL,SL); /LED灯显示秒或模式灯 display_LED u12(DSH,SH); mode_choose u13(mode_flag,Keydone2,_250ms,co1,co2,set_co2,co11,co22,co111,co222); /选择模式进行不同操作 hour12_24 u14(HH

6、24,HL24,HH12,HL12); /12-24小时切换 boshi u15(HH,HL,MH,ML,SH,SL,_1HZ,bao_signal); /整点报时 set_naozhong u16(co111,co222,set_HH,set_HL,set_MH,set_ML,set_co2); /设置闹钟时间 Naozhong u17(Alarm_ctr,_500ms,set_HH,set_HL,set_MH,set_ML,HH24,HL24,MH24,ML24,nao_signal); /任意闹钟响应 LUT_mode u18(mode_flag,H12_24,HH12,HL12,HH2

7、4,HL24,MH24,ML24,set_HH,set_HL,set_MH,set_ML,MH,ML,HH,HL);/通过模式选择数码管显示 LED_mode u19(mode_flag,SH24,SL24,SH,SL); 模式选择LED灯显示 Endmodule 分频模块 : 分频模块的作用主要是要获得各种频率的时钟信号。输入信号为50MHZ的信号,要想获得1HZ的信号作为秒脉冲计时,则要对50MHZ信号分频。通过计数的方式,当计数从0开始到24 999999时,1HZ信号取反一次,计数又从0开始,如此循环,就可以得到1HZ脉冲信号。对于其他信号也是如此,只是计数值不一样,得到的分频信号不同

8、。 module devide_f(_1HZ,_10ms,_250ms,_500ms,nCR,_50MHZ); input _50MHZ,nCR; output _1HZ,_10ms,_250ms,_500ms; reg _1HZ,_10ms,_250ms,_500ms; reg31:0Q1,Q2,Q3,Q4; always(posedge _50MHZ or negedge nCR)begin if(nCR) begin Q1=32d0; Q2=32d0; Q3=32d0; Q4=32d0; end begin Q1=32d249999) begin Q2=32d6299999) begin

9、 Q4=32d0; _250ms=_250ms; end begin Q3=32d0; _500ms=_500ms; end else begin Q1=Q1+1d1; Q2=Q2+1d1; Q3=Q3+1d1; Q4=Q4+1d1; end end endmodule 计时模块: 秒计数:在1HZ脉冲下进行秒计时,当计时达到59秒后,在下一个脉冲来临变0,并发出一个脉冲信号,可供下面分钟计数作为输入脉冲信号计时。 分钟计数:在输入脉冲下,分钟开始计时,当计时达到59后,在下一个脉冲来临变0,并发出一个脉冲,供小时计数的输入脉冲新号。 小时计数:脉冲信号来临时,计数加1,达到23后在下一个脉冲

10、的作用下清零,从新计时。如果有复位信号,则时分秒全部清零。 module second(cp,reset,mode_flag,BT2,SH,SL,co); input cp,reset,BT2; input3:0mode_flag; output co=1b0; reg co; output 3:0SL,SH; reg3:0SH,SL; reg7:0cnt; always(posedge cp or negedge reset ) begin if(!reset) begin SL=4b0; SH=4b0; cnt=8b0; end else if(mode_flag=4b0010)&(!BT

11、2) begin SL=4b0; SH=4b0; cnt=8b0; end else begin if(cnt=8d59) begin cnt=8d0; SH=4d0; SL=4d0; co=1b1; end else begin co=1b0; cnt=cnt+8d1; SL=cnt_x0010_; SH=cnt/10; end end end endmodule module minute (cp,reset,MH,ML,co); input cp ,reset; output co=1b0; output 3:0ML,MH; reg3:0MH,ML; reg7:0cnt; reg co;

12、 always(posedge cp or negedge reset) begin if(!reset) begin ML=4b0; MH=4b0; cnt=8b0; end else begin if(cnt=8d59) begin cnt=8d0; MH=4d0; ML=4d0; co=1b1; end else begin co=1b0; cnt=cnt+8d1; ML=cnt_x0010_; MH=cnt/10; end end end endmodule module hour (cp,reset,HH,HL); input cp,reset; output 3:0HL,HH; r

13、eg3:0HH,HL; reg7:0cnt; always(posedge cp or negedge reset) begin if(!reset) begin HL=4b0; HH=4b0; cnt=8b0; end else begin if(cnt=8d23) begin cnt=8d0; HH=4d0; HL=4d0; end else begin cnt=cnt+8d1; HL=cnt_x0010_; HH=cnt/10; end end end Endmodule 模式选择模块 : 同过一个模式档按键MODE,按一下产生对应一种模式mode_flag,并且可以循环。在不同的模式下

14、可以进行不同的操作。其中mode_flag=40000为正常显示计时,mode_flag=40001为小时调钟模式,mode_flag=400010为分钟调钟模,mode_flag=40011为闹钟小时设置模式,mode_flag=40100为闹钟分钟设置模式。 module key_press(_10ms,KEY,Keydone); input KEY,_10ms; output Keydone; reg dout1,dout2,dout3; always (posedge _10ms) begin dout1 = KEY; dout2 = dout1; dout3 = dout2; end

15、 assign Keydone = (dout1 | dout2 | dout3); endmodule module mode (MODE,mode_flag); input MODE ; output 3:0mode_flag; reg 3:0mode_flag; always (negedge MODE ) begin mode_flag = mode_flag+ 4b1; if(mode_flag = 4b0101) mode_flag = 2b0; end endmodule module LED_mode (mode_flag,SH24,SL24,SH,SL); input 3:0

16、 mode_flag; input 3:0 SH24,SL24; output 3:0SH,SL; reg 3:0SH,SL; always(mode_flag )begin case (mode_flag) 4b0000:begin SH=SH24; SL=SL24;end 4b0001: begin SH=4b0000; SL=4b0001;end 4b0010: begin SH=4b0000; SL=4b0010;end 4b0011: begin SH=4b0000; SL=4b0100;end 4b0100: begin SH=4b0000; SL=4b1000;end defau

17、lt : begin SH=SH24; SL=SL24;end endcase end endmodule Module LUT_mode (mode_flag,H12_24,HH12,HL12,HH24,HL24,MH24,ML24,set_HH,set_HL,set_MH,set_ML,MH,ML,HH,HL); input 3:0 HH12,HL12,HH24,HL24,MH24,ML24; input 3:0 set_HH,set_HL,set_MH,set_ML; input 3:0 mode_flag; input H12_24; output 3:0 MH,ML,HH,HL; r

18、eg 3:0 MH,ML,HH,HL; always(mode_flag or H12_24) begin case (mode_flag) 4b0011, 4b0100: begin HH=set_HH; HL=set_HL; MH=set_MH; ML=set_ML; end default:begin if(H12_24)begin HH=HH12; HL=HL12; MH=MH24; ML=ML24;end else begin HH=HH24; HL=HL24; MH=MH24; ML=ML24;end end endcase end endmodule module mode_ch

19、oose(mode_flag,BT2,_250ms,co1,co2,set_co2,co11,co22,co111,co222); input 3:0mode_flag; input BT2,_250ms,co1,co2,set_co2; output co11,co22,co111,co222; supply1 Vdd; reg co11,co22,co111,co222; always(mode_flag)begin case (mode_flag) 4b0001: begin if(BT2) co22=_250ms; else begin co22=co2; co11=co1; end

20、end 4b0010: begin if(BT2) begin co11=_250ms; co22=co2;end else begin co11=co1; co22=co2; end end 4b0011: begin co22=co2; co11=co1; if(BT2) co222=_250ms; else co222=set_co2;end 4b0100: begin co22=co2; co11=co1; if(BT2) co111=_250ms; else co111=Vdd; end default :begin co11=co1; co22=co2; end endcase e

21、nd endmodule 闹钟模块 : module set_naozhong(co111,co222,set_HH,set_HL,set_MH,set_ML,co2); input co111,co222; output 3:0set_HH,set_HL,set_MH,set_ML; supply1 Vdd; output co2; minute (co111,Vdd,set_MH,set_ML,co2); hour (co222,Vdd,set_HH,set_HL); endmodule modulenaozhong (Alarm_ctr,_1HZ,set_HH,set_HL,set_MH

22、,set_ML,HH24,HL24,MH24,ML24,nao_signal); input Alarm_ctr,_1HZ; input 3:0 set_HH,set_HL,set_MH,set_ML; input 3:0 HH24,HL24,MH24,ML24; output nao_signal; reg signal; reg nao_signal; reg 16:0 Q; always(posedge _1HZ)begin if(signal)&(Alarm_ctr)begin if(set_HH=HH24)&(set_HL=HL24)&(set_MH=MH24)&(set_ML=ML

23、24)signal=1b1; else signal=1b0;end else if(signal)&(Alarm_ctr)begin nao_signal=8d720)begin Q=16b0; signal=1b0;end end else begin signal=1b0; nao_signal=1b0;end end endmodule 1224小时切换模块: module hour12_24(HH24,HL24,HH12,HL12); input 3:0 HH24,HL24; output 3:0 HH12,HL12; reg 3:0 HH12,HL12; reg flag; alw

24、ays(HH24 or HL24)begin if(HH24*10+HL24)=12) begin HH12=HH24; HL12=13)&(HH24*10+HL24)=19) begin HH12=4d0; HL12=19)&(HH24*10+HL24)=21) begin HH12=4d0; HL12=HL24+4d8; end else begin HH12=HH24-4d1; HL12=HL24-4d2; end end endmodule 整点报时模块: module boshi(HH,HL,MH,ML,SH,SL,_500ms,bao_signal); input3:0 HH,HL

25、,MH,ML,SH,SL; input _500ms; output bao_signal; reg bao_signal; reg 7:0Q1,Q2; reg bao; always(posedge _500ms)begin if(SH*10+SL)=8d59)&(MH*10+ML)=8d59)begin Q1=7b0; bao=1b1;end else if(Q110*HH+HL)&(bao) begin bao_signal=bao_signal; Q1=Q1+bao_signal; end else if(Q1=(10*HH+HL) bao=1b0; else begin bao_si

26、gnal=1b0; end end endmodule 译码显示模块: 一、数码管显示:通过传入响应的4位十进制数,运用case语句转换输出相应的8位二进制显示码,送入数码管显示。 二、LED显示 : module display_LED(s_out,s_int); input3:0s_int; output3:0s_out; reg3:0s_out; wire 3:0s_out1; always (s_int) begin case(s_int) 4h0:s_out=4b0000; 4h1:s_out=4b0001; 4h2:s_out=4b0010; 4h3:s_out=4b0011; 4h4:s_out=4b0100; 4h5:s_out=4b0101; 4h6:s_out=4b0110; 4h7:s_out=4b0111; 4h8:s_out=4b1000; 4h9:s_out=4b1001; endcase end assign s_out1=s_out; Endmodule module SEG7_LUT(oSEG1,iDIG); input3:0iDIG; output7:0oSEG1; reg7:0oSEG; wire 7:0oSEG1; always (iDIG) begin case(iDIG) 4h0: oS

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1