verilog数字钟代码.doc_第1页
verilog数字钟代码.doc_第2页
verilog数字钟代码.doc_第3页
verilog数字钟代码.doc_第4页
verilog数字钟代码.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

module digclk(clk,en,rst,dula,wela,s1,s2,s3,led,flag1,start1,flag2,start2,aled,s6,s4,s5); /s1调时 s2调分 s3调秒 wela位码 dula段码 en使能 clk时钟,flag1是跑表标志(拨上去就是显示跑表),置一为跑表功能,start1为跑表开始停止/flag2为闹钟标志(拨上去就是设置闹钟时间) start2为闹钟开关 aled闹钟提示灯input clk,rst,en,s1,s2,s3,flag1,start1,flag2,start2,s6,s4,s5;output 2:0 wela;output 7:0 dula;output led;output aled;reg led;reg aled;reg 7:0 cnt,dula;reg 2:0 wela;reg7:0 hourh,hourl,minh,minl,sech,secl;reg7:0 phourh,phourl,pminh,pminl,psech,psecl;reg7:0 ahourh,ahourl,aminh,aminl,asech,asecl;reg3:0 a; /a用于数码管显示的临时变量(* synthesis, keep *) reg clk1;always (posedge clk1)beginif(start2)beginif(hourh=ahourh&hourl=ahourl&minh=aminh&minl=aminl&sech=asech&secl=asecl) aled=1b1;else aled=1b0;endendalways (posedge clk1) /闹钟功能beginif(flag2)beginif(!s4) /调节小时 begin /*if(ahourl=9)begin ahourl=0;ahourh=ahourh+1;end if(ahourh=2&ahourl=3)begin ahourh=0;ahourl=0; end else ahourl=ahourl+1;*/ ahourl=ahourl+1; if(ahourl=3&ahourh=2)begin ahourl=0;ahourh=0;end if(ahourl=9) begin ahourl=0;ahourh=ahourh+1;end; end else if(!s5) /调节分钟 begin if(aminl=9) begin aminl=0; if(aminh=5) aminh=0; else aminh=aminh+1; end else aminl=aminl+1; endelse if(!s6) /调节秒钟(调节都是在暂停的前提下)beginif(asecl=9)beginasecl=0;if(asech=5) asech=0;else asech=asech+1;endelse asecl=asecl+1; endendendalways (posedge clk1)/用于跑表beginif(flag1&start1)beginif(psecl=9) /时钟正常跳动状态 begin psecl=0; if(psech=5) begin psech=0; if(pminl=9) begin pminl=0; if(pminh=5) begin pminh=0; if(phourl=9) begin phourl=0;phourh=phourh+1;end else if(phourh=2&phourl=3) begin phourl=0; phourh=0;end else phourl=phourl+1; end else pminh=pminh+1; end else pminl=pminl+1; end else psech=psech+1; end else psecl=psecl+1;endelse if(!flag1) begin psecl=0;psech=0;pminl=0;pminh=0;phourl=0;phourh=0; endendalways (posedge clk)/用于分频begincnt=cnt+1;if(cnt=200) begin clk1=1b1; cnt=0; endelse clk1=1b0; /200分频,CLK为数码管扫描频率,CLK1为计数频率if(wela7) wela=wela+1; else wela=0;endalways (posedge clk1)/整点报时beginif(minh=0&minl=0&sech=0&secl=0)led=1b1;else led=1b0;endalways (posedge clk1 or negedge rst) /这里负责处理使能和复位 暂停调时 使能处于开的时候则是正常显示beginif(!rst) begin secl=0;sech=0;minl=0;minh=0;hourl=0;hourh=0; endelse if(!en) /时钟暂停,开始调时beginif(!s1) /调节小时 begin /*if(hourh=2&hourl=4)begin hourl=0;hourh=0; end else if(hourl=9)begin hourl=0;hourh=hourh+1;end else hourl=hourl+1;*/ hourl=hourl+1; if(hourl=3&hourh=2)begin hourl=0;hourh=0;end if(hourl=9) begin hourl=0;hourh=hourh+1;end; end else if(!s2) /调节分钟 begin if(minl=9) begin minl=0; if(minh=5) minh=0; else minh=minh+1; end else minl=minl+1; endelse if(!s3) /调节秒钟(调节都是在暂停的前提下)beginif(secl=9)beginsecl=0;if(sech=5) sech=0;else sech=sech+1;endelse secl=secl+1;end end else if(secl=9) /时钟正常跳动状态 begin secl=0; if(sech=5) begin sech=0; if(minl=9) begin minl=0; if(minh=5) begin minh=0; if(hourl=9) begin hourl=0;hourh=hourh+1;end else if(hourh=2&hourl=3) begin hourl=0; hourh=0;end else hourl=hourl+1; end else minh=minh+1; end else minl=minl+1; end else sech=sech+1; end else secl=secl+1;endalways (wela)/用于数码管显示beginif(flag1&!flag2)begin case(wela)0:a=phourh;1:a=phourl;2:a=12;3:a=pminh;4:a=pminl;5:a=12;6:a=psech;7:a=psecl;default: a=0;endcasecase(a)0:dula=8b00111111; 1:dula=8b00000110;2:dula=8b01011011; 3:dula=8b01001111; 4:dula=8b01100110; 5:dula=8b01101101;6:dula=8b01111101; 7:dula=8b00000111; 8:dula=8b01111111; 9:dula=8b01101111; /8段译码值 是倒着看的12:dula=8b01000000;default:dula=8b11111111;endcaseendelse if(flag2&!flag1)begincase(wela)0:a=ahourh;1:a=ahourl;2:a=12;3:a=aminh;4:a=aminl;5:a=12;6:a=asech;7:a=asecl;default: a=0;endcasecase(a)0:dula=8b00111111; 1:dula=8b00000110;2:dula=8b01011011; 3:dula=8b01001111; 4:dula=8b01100110; 5:dula=8b01101101;6:dula=8b01111101; 7:dula=8b00000111; 8:dula=8b01111111; 9:dula=8b01101111; /8段译码值12:dula=8b01000000;default:dula=8b11111111;endcaseendelse begincase(wela)0:a=hourh;1:a=hourl;2:a=12;3:a=minh;4:a=minl;5:a=12;6:a=sech;7:a=secl;default: a=0;endcasecase(a)0:dula=8b00111111; 1:dula=8b00000110;2:dula=8b0101101

温馨提示

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

评论

0/150

提交评论