马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
哪位好心人可以帮忙仿真一下么
主程序如下:
module clock (clr_key,clk,segdat,sl);
input clr_key,clk;
output [7:0] segdat;
output [3:0] sl;
reg [23:0] count;
reg [7:0] sec,min;
reg [7:0] segdat_reg;
reg [3:0] sl_reg;
reg [3:0] disp_dat;
reg second,second_1;
reg cn;
always @(posedge clk or negedge clr_key)
begin
if (!clr_key)
begin
count<=0;
second_1<=0;
end
else
begin
if (count==24'd12499999)
begin
count<=0;
second_1<=~second_1;
end
else
begin
count<=count+1;
end
end
end
always@(posedge second_1 or negedge clr_key)
begin
if (!clr_key)
second<=0;
else
second<=~second;
end
always@ (count[11:10])
begin
case (count[11:10])
2'b00:disp_dat=sec[3:0];
2'b01:disp_dat=sec[7:4];
2'b10:disp_dat=min[3:0];
2'b11:disp_dat=min[7:4];
endcase
end
always@(disp_dat)
begin
case (disp_dat)
4'h0:segdat_reg=8'hc0;
4'h1:segdat_reg=8'hf9;
4'h2:segdat_reg=8'ha4;
4'h3:segdat_reg=8'hb0;
4'h4:segdat_reg=8'h99;
4'h5:segdat_reg=8'h92;
4'h6:segdat_reg=8'h82;
4'h7:segdat_reg=8'hf8;
4'h8:segdat_reg=8'h80;
4'h9:segdat_reg=8'h90;
endcase
if ((count[11:10]==2'b10)&second)
segdat_reg=segdat_reg&8'b01111111;
end
always @(count[11:10])
begin
case (count[11:10])
2'b00:sl_reg=4'b1110;
2'b01:sl_reg=4'b1101;
2'b10:sl_reg=4'b1011;
2'b11:sl_reg=4'b0111;
endcase
end
always @(posedge second or negedge clr_key)
begin
if (!clr_key)
begin
sec[7:0]=8'h0;
cn=0;
end
else
begin
cn=0;
sec[3:0]=sec[3:0]+1;
if (sec[3:0]==4'd10)
begin
sec[3:0]=4'd0;
sec[7:4]=sec[7:4]+1;
if(sec[7:4]==4'd6)
begin
sec[7:4]=4'd0;
cn=1;
end
end
end
end
always@(posedge cn or negedge clr_key)
begin
if (!clr_key)
begin
min[7:0]=8'h0;
end
else
begin
min[3:0]=min[3:0]+1;
if (min[3:0]==4'd10)
begin
min[3:0]=4'd0;
min[7:4]=min[7:4]+1;
if(min[7:4]==4'd6)
begin
min [7:4]=4'd0;
end
end
end
end
assign segdat=segdat_reg;
assign sl=sl_reg;
endmodule
testbench:
`timescale 1ns/ 1ns
module clock_vlg_tst();
reg clk;
reg clr_key;
wire [7:0] segdat;
wire [3:0] sl;
clock i1 (
.clk(clk),
.clr_key(clr_key),
.segdat(segdat),
.sl(sl)
);
initial
begin
clk=0;
clr_key=0;
#100 clr_key=1;
#3000000000 clr_key=0;
#1000 $stop;
end
always #10 clk=~clk;
endmodule
仿真图形如下图所示,数码管上只是循环显示0和1
|