moduleCLK_to_clk
#(parameter T1MS =7500000)(
input CLK,rst,
output clk
);
reg [32:0]count;
always @(posedge CLK,posedge rst)
begin
if(rst)
count<=0;else
begin
if(count < T1MS)
count<= count+1;else count <=0;
end
end
assign clk =(count==T1MS)?1:0;
endmodule
modulestopwatch(
input CLK,rst,
input go,up,// up信号 =1 则 倒计时
output reg [3:0]M,D,
output reg [5:0]SS
);
wire clk;
CLK_to_clk C(CLK,rst,clk);
reg [3:0]M_next,D_next;
reg [5:0]SS_next;
always@(posedge CLK,posedge rst)
begin
if(rst)
begin
M <=4'b0;
D <=4'b0;
SS <=6'b0;
end
elseif(go ==1)
begin
M <= M_next;
D <= D_next;
SS <= SS_next;
end
end
always @(posedge clk,posedge rst)
begin
if(rst)
begin
D_next <=0;
SS_next <=0;
M_next <=0;
end
else begin
if(up==1)
begin
if(D !=9)
D_next = D +1;else
begin
D_next =4'd0;if(SS