Verilog 时钟电路.docx_第1页
Verilog 时钟电路.docx_第2页
Verilog 时钟电路.docx_第3页
Verilog 时钟电路.docx_第4页
Verilog 时钟电路.docx_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

该时钟电路针对的是50MHZ FPGA实验器材:FPGA芯片,两个四位一体数显管,一个按键,若干导线采用模块化设计,将电路分成分频模块,时钟计数模块,数显轮显模块,数显代码转换模块四个模块。时钟计数又分60进制计数模块,24进制计数模块。程序代码:上层模块:module clock(clk,clr,data,yiwei);input clk,clr;output5:0 yiwei;output6:0 data;wire clk,clk1,clk2,clk3,clk4,reset,clr,cin_sec;wire7:0 hour,min,sec,qout_hour,qout_sec,qout_min;wire5:0 yiwei,wei;wire3:0 dec_in,out;wire6:0 data,decodeout;assign clk3=clk1;assign hour7:0=qout_hour7:0;assign min7:0=qout_min7:0;assign sec7:0=qout_sec7:0;assign reset=clr;assign yiwei5:0=wei5:0;assign dec_in3:0=out3:0;assign data6:0=decodeout6:0;assign cin_sec=1;assign clk4=clk2;clock_time times(clk3,reset,qout_sec,qout_min,qout_hour,cin_sec);fp fenpin(clk,clk1,clk2);decode47 decode(decodeout,dec_in);led xianshi(clk4,wei,out,hour,min,sec);endmodule计数模块:module clock_time(clk,reset,qout_sec,qout_min,qout_hour,cin_sec);input clk,reset,cin_sec;wire clk_sec,clk_min,clk_hour,clk,c1,c2;wire cin_sec,cin_min,cin_hour,reset1,cout_sec,cout_min,cout_hour;output7:0 qout_sec,qout_min,qout_hour;wire7:0 qout_sec,qout_min,qout_hour,qout_sec1,qout_min1,qout_hour1;assign cin_min=cout_sec;assign cin_hour=cout_min;assign qout_sec7:0=qout_sec17:0;assign qout_min7:0=qout_min17:0;assign qout_hour7:0=qout_hour17:0;assign reset1=reset; counter60 sec(qout_sec1,cout_sec,cin_sec,reset,clk);counter60 min(qout_min1,cout_min,cin_min,reset1,clk);counter24 hour(qout_hour1,cout_hour,cin_hour,reset1,clk);endmodule60进制模块:module counter60(qout,cout,cin,reset,clk);input cin,clk,reset;output7:0 qout;wire cin,clk,reset;output cout;reg7:0 qout;always(posedge clk) begin if(reset) qout=8d0; else if(cin) begin if(qout3:0=4b1001) begin qout3:0=4b0000; if(qout7:4=4b0101) qout7:4=4b0000; else qout7:4=qout7:4+4b0001; end else qout3:0=qout3:0+4b0001; end endassign cout=(qout7:0=8b01011001)&cin)?1b1:1b0;endmodule24进制模块:module counter24(qout,cout,cin,reset,clk);input cin,clk,reset;output7:0 qout;output cout;reg7:0 qout;always(posedge clk) begin if(reset) qout=0; else if(cin) begin if(qout3:0=3) begin if(qout7:4=2) begin qout7:4=0; qout3:0=0; end else qout3:0=qout3:0+4b0001; end else if(qout3:0=9) begin qout3:0=0; qout7:4=qout7:4+4b0001; end else qout3:0=qout3:0+4b0001; end endassign cout=(qout7:0=8b00100011)&cin)?1b1:1b0;endmodule分频模块:因为电路本身的时钟是50MHZ必须要分频,用来提供时间计数的1HZ和轮显频率,轮显频率过高会造成无法显示的问题,轮显控制在毫秒级。module fp(clk,clk1,clk2);input clk;output clk1,clk2;reg clk1;reg clk2;reg17:0 con1;reg24:0 con;always(posedge clk) if(con24:0=25d5000000) begin clk1=clk1; con=0; end else con24:0=con24:0+25b0000000000000001;always(posedge clk) if(con117:0=100000) begin clk2=clk2; con1=0; end else con117:0=con117:0+18b0000000000000001;endmodule数显管轮显模块:由于四位一体的数显管是数据输入共用的,所以必须采用轮显,才能实现不同数显管显示相应的内容。module led(clk,wei,out,hour,min,sec);input7:0 hour,min,sec;input clk;output5:0 wei;output3:0 out;reg3:0 out;reg5:0 wei;reg2:0 m;always(posedge clk) begin case(m) 0:begin wei5:0=6b111110;out=sec3:0;end 1:begin wei5:0=6b111101;out=sec7:4;end 2:begin wei5:0=6b111011;out=min3:0;end 3:begin wei5:0=6b110111;out=min7:4;end 4:begin wei5:0=6b101111;out=hour3:0;end 5:begin wei5:0=6b011111;out=hour7:4;end endcase if (m=5) m=0; else m=m+1;endendmodule代码转换模块:由于计数输出时BCD码,直接作为数显管的信号输入肯定是不行的,必须要转换成相应的代码。module decode47(decodeout,dec_in);input3:0 dec_in;output6:0 decodeout;reg6:0 decodeout;always(dec_in) begin case(dec_in) 4d0:decodeout=7b1111110; 4d1:decodeout=7b0110000; 4d2:decodeout=7b1101101; 4d3:decodeout=7b1111001; 4d4:decodeout=7b0110011; 4d5:decodeout=7b

温馨提示

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

评论

0/150

提交评论