用verilog设计一数字钟系统
来源:互联网 发布:java实现高斯模糊 编辑:程序博客网 时间:2024/04/30 14:29
二.设计一数字钟系统,要求如下:
1. 有基础的实时数字钟功能,即时,分,秒的正常显示模式。(24小时制)
2. 可对系统用手动方式校准,设计两个按键,按动校时键,时计数器加一,按动校分键,则电路处于校分状态。
3. 整点报时,要求在59分50秒,52秒,54秒,56秒和58秒发出一个低音信号,00分00秒发出一个高音信号。
源程序如下:
module clock (clk,reset,hour_g,hour_d,minute_g,minute_d,second_g,second_d,add_s,add_f,lowalarm,highalarm); input clk,reset,add_s,add_f;output[3:0] hour_g,hour_d,minute_g,minute_d,second_g,second_d;reg[3:0] hour_g,hour_d,minute_g,minute_d,second_g,second_d;wire cout_s,cout_m;reg[3:0] jishi;output lowalarm,highalarm;//低音和高音信号reg lowalarm;wire highalarm;always @(posedge clk)begin if(!reset) second_d<=0; else if(second_d==9) second_d<=0; else second_d<=second_d+1;endalways @(posedge clk)begin if(!reset) second_g<=0; else if(second_d==9) begin if(second_g==5) second_g<=0; else second_g<=second_g+1; end endassign cout_s=((second_d==9)&&(second_g==5))?1:0;always @(posedge clk)begin if(!reset) minute_d <= 0; else if(cout_s) begin if(minute_d==9) minute_d <= 0; else minute_d <=minute_d+1; endendalways @(posedge clk)begin if(!reset) minute_g <= 0; else if(cout_s) begin if(minute_d==9) begin if(minute_g==5) minute_g <= 0; else minute_g<= minute_g+1; end endendassign cout_m = ((minute_d==9)&&(minute_g==5))?1:0;always @(posedge clk)begin if(!reset) hour_d <= 0; else if(cout_m&&cout_s) begin if((hour_d==3)&&(hour_g==2)) hour_d<=0; else if(hour_d==9) hour_d <=0; else hour_d <= hour_d + 1; endendalways @(posedge clk)begin if(!reset) hour_g <= 0; else if(cout_m&&cout_s) begin if((hour_d==3)&&(hour_g==2)) hour_g <= 0; else if(hour_d==9) hour_g<=hour_g+1; endendalways @(posedge clk)begin if(add_s) begin if((hour_d==3)&&(hour_g==2)) begin hour_g<=0; hour_d<=0; end else if(hour_d==9) begin hour_d<=0; hour_g<=hour_g+1; end else hour_d<=hour_d+1; end end always @(posedge clk) begin if(add_f) begin if((minute_d==9)&&(minute_g==5)) begin minute_d<=0; minute_g<=0; end else if(minute_d==9) begin minute_d<=0; minute_g<=minute_g+1; end else minute_d<=minute_d+1; end end always @(posedge clk) begin if(!reset) begin lowalarm<=0; jishi<=1; end else if((minute_g==5)&&(minute_d==9)) begin if(second_g==5) begin if((second_d==1)||(second_d==3)||(second_d==5)||(second_d==7)) lowalarm<=1; else begin lowalarm<=0; jishi<=jishi+1; end end if(second_g==4&&second_d==9) lowalarm<=1; end end assign highalarm=((minute_g==0)&&(minute_d==0)&&(second_g==0)&&(second_d==0))?1:0; endmodule
测试程序如下:
`timescale 1ns/1nsmodule clock_tb(); reg clk,reset; wire[3:0] hour_g,hour_d,minute_g,minute_d,second_g,second_d; wire lowalarm,highalarm; reg add_s,add_f; clock u1(.clk(clk),.reset(reset),.hour_g(hour_g),.hour_d(hour_d),.minute_g(minute_g), .minute_d(minute_d),.second_g(second_g),.second_d(second_d),.add_s(add_s),.add_f(add_f),.lowalarm(lowalarm),.highalarm(highalarm)); parameter DELY=100; always #(DELY/2) clk=~clk; initial begin clk=0;add_s=0;add_f=0;reset=0; #150 reset=1; #(DELY*100000) add_s=1; #DELY add_s=0; #(DELY*5) add_f=1; #DELY add_f=0; #DELY $finish; endendmodule
0 0
- 用verilog设计一数字钟系统
- verilog 数字系统设计教程 读书笔记(1)
- verilog 数字系统设计教程 读书笔记(2)
- [转]Verilog数字系统设计教程(大连理工一博士学习笔记)
- [转]Verilog数字系统设计教程(大连理工一博士学习笔记)
- 基于basys2用verilog设计多功能数字钟(重写)
- 基于basys2用verilog设计多功能数字钟(重写)
- 基于basys2用verilog设计多功能数字钟(重写)
- 基于basys2用verilog设计多功能数字钟(重写)
- verilog数字系统要点
- [verilog读书笔记]1.Verilog HDL数字设计
- Verilog实现数字钟
- verilog HDL数字钟Quartus工程
- FPGA Verilog语言实现数字钟
- Verilog HDL数字设计与综合 笔记(1)
- Verilog HDL数字设计与综合 笔记(2)
- 基于CPLD的数字钟设计(一)
- 二级项目:数字系统设计——数字钟系统设计
- 菜鸟到大神的上位历程,即学即用走向人生巅峰(大神学习经验)
- 第九周项目1-猴子选大王数组版
- 秩为1的矩阵,向量,绩的联合使用
- 正则表达式的运算符优先级
- docker镜像制作之Dockerfile文件---hadooop伪分布式
- 用verilog设计一数字钟系统
- 第八周oj题目求倒数和
- Android系统信息与安全机制
- HDU 1873 看病要排队 (优先队列)
- Intel Edison用mjpg-streamer进行视频传输
- Children of the Candy Corn(图的遍历bfs最小步数)
- @contextmanager:Python实现with结构的好方法
- ajax
- C++中int转化为string