- 21
- 0
- 约3.32千字
- 约 11页
- 2017-05-06 发布于湖北
- 举报
用VerilogHDL语言编写的电子秒表讲述
电子秒表;本设计是用Verilog HDL语言编写的电子秒表,精度为0.01秒,用两个按键来操作秒表(开始/暂停按键和重置按键),并用四段数码管显示。
程序中的数码管驱动模块是根据BASYS 2开发板数码管电路编写的。;代码如下:
//总模块
module miao_biao(rest,clk,a_to_g,A_TO_D,kon,clk001
);
input wire rest; //复位
input wire clk; //50M时钟
output wire clk001; //输出0.01S的脉冲
wire [3:0]q0; //每一位上的数据,公四位
wire [3:0]q1;
wire [3:0]q2;
wire [3:0]q3;
wire Q0; //每一位计到0后,Q变为1,作为下一片的脉冲信号
wire Q1;
wire Q2;
output wire [6:0]a_to_g;
output wire [3:0]A_TO_D;
input wire kon;
Wire clk001out;
//以上是各个网络的定义,clk001可以不用当做输出;//以下是各个模块的连接,以及各个模块的调用
assign Q0=~(q0[0]|q0[1]|q0[2]|q0[3]);
assign Q1=~(q1[0]|q1[1]|q1[2]|q1[3]);
assign Q2=~(q2[0]|q2[1]|q2[2]|q2[3]);
jian_kong jian_kong0(rest,kon,clk001,clk001out);
cp_001s cp_001s0(rest,clk,clk001);
count4 count4_0(clk001out,rest,q0);
count4 count4_1(Q0,rest,q1);
count4 count4_2(Q1,rest,q2);
count4 count4_3(Q2,rest,q3);
shumaguan shumaguan0(a_to_g,A_TO_D,clk,q3,q2,q1,q0);
Endmodule
//到此总模块结束;module count4(a,clr,q); //计数器,从9计到0
input wire a;
input wire clr;
output reg [3:0]q;
always@(posedge a or posedge clr)
begin
if(clr==1)
q=0;
else if(q==9)
q=0;
else
q=q+1;
end
endmodule
//该模块的十进制计数器,每一位的数据由一个该计数器提供;Module shumaguan(a_to_g,A_TO_D,clk,qian,bai,shi,ge);//数码管驱动
output reg [6:0]a_to_g;
output reg [3:0]A_TO_D;
input wire clk;
input wire [3:0]qian;
input wire [3:0]bai;
input wire [3:0]shi;
input wire [3:0]ge;
reg [3:0]duan;
reg [1:0]wei;
reg a;
reg [16:0]q;
always@(posedge clk)
begin
if(q==49999)
begin
q=0;
a=~a;
end
else
q=q+1;
end;always@(*)//7位段译码
case(duan)
0:a_to_g=7b0000001;
1:a_to_g=7b1001111;
2:a_to_g=7b0010010;
3:a_to_g=7b0000110;
4:a_to_g=7b1001100;
5:a_to_g=7b0100100;
6:a_to_g=7b0100000;
7:a_to_g=7b0001111;
8:a_to_g=7b0000000;
9:a_to_g=7b0000100;
default:a_to_g=7b0000001;
endcase;always@(*)//4位位选译码
case(wei)
3:begin
A_TO_D=4b1110;
duan=qian;
end
2:begin
A_TO_D=4b1101;
duan=bai;
end
1:begin
A_TO_D=4b1011;
duan=shi;
end
0:begin
A_TO_D=4b0111;
duan=ge;
end
default:A_TO_D=4b1110;
en
原创力文档

文档评论(0)