module top_module (
input clk,
input reset, // Synchronous active-high reset
output [3:0] q);
always@(posedge clk) begin
if(reset)
q<=0;else if(q=='d9) begin
q<=0; end
else begin
q<=q+1; end
end
endmodule
module top_module (
input clk,
input slowena,
input reset,
output [3:0] q);
always@(posedge clk) begin
if(reset)
q<=0;else begin
if(slowena) begin
if(q=='d9)
q<=0;else
q<=q+1;
end
else
q<=q;
end
end
endmodule
module top_module(
input clk,
input reset,
input ena,
output reg pm,
output [7:0] hh,
output [7:0] mm,
output [7:0] ss);
wire ss_en,ss_60_en;
reg [3:0] ss_one,ss_ten;
wire mm_en,mm_60_en;
reg [3:0] mm_one,mm_ten;
wire hh_en,pm_en;
reg [3:0] hh_one,hh_ten;
assign ss ={ss_ten,ss_one};
assign mm ={mm_ten,mm_one};
assign hh ={hh_ten,hh_one};
always @(posedge clk) begin
if(reset) begin
ss_one <=4'b0;
end
else if(ena) begin
if (ss_one == 4'd9) begin
ss_one <=4'b0;
end
else
ss_one <= ss_one + 1'b1;
end
end
assign ss_en =((ss_one ==4'd9)&& ena)?1'b1 :1'b0;
always @(posedge clk) begin
if (reset) begin
ss_ten <=4'b0;
end
else if(ss_en) begin
if ((ss_one ==4'd9)&&(ss_ten ==4'd5)&& ena) begin
ss_ten <=4'b0;
end
else
ss_ten <= ss_ten +1'b1;
end
end
assign ss_60_en =((ss_one ==4'd9)&&(ss_ten ==4'd5)&& ena)?1'b1 :1'b0;
always @(posedge clk) begin
if (reset) begin
mm_one <=4'b0;
end
else if(ss_60_en) begin
if (mm_one ==4'd9) begin
mm_one <=4'b0;
end
else
mm_one <= mm_one +1'b1;
end
end
assign mm_en =((mm_one ==4'd9)&&(ss_one ==4'd9)&&(ss_ten ==4'd5)&& ena)?1'b1 :1'b0;
always @(posedge clk) begin
if (reset) begin
mm_ten <=4'b0;
end
else if(mm_en) begin
if ((mm_one ==4'd9)&&(mm_ten ==4'd5)&& ena &&(ss_one ==4'd9)&&(ss_ten ==4'd5)) begin
mm_ten <=4'b0;
end
else
mm_ten <= mm_ten + 1'b1;
end
end
assign mm_60_en =((mm_one ==4'd9)&&(mm_ten ==4'd5)&& ena &&(ss_one ==4'd9)&&(ss_ten ==4'd5)) ? 1'b1 : 1'b0;
always @(posedge clk) begin
if(reset) begin
hh_one <=4'd2;
end
else if(mm_60_en) begin
if ((hh_one == 4'd2)&&(hh_ten ==4'd1) && (mm_one == 4'd9)&&(mm_ten ==4'd5) && ena && (ss_one == 4'd9)&&(ss_ten ==4'd5)) begin
hh_one <= 4'd1;
end
elseif((hh_one ==4'd9)&&(hh_ten ==4'd0)&&(mm_one ==4'd9)&&(mm_ten ==4'd5)&& ena &&(ss_one ==4'd9)&&(ss_ten ==4'd5)) begin
hh_one <=4'd0;
end
else
hh_one <= hh_one + 1'b1;
end
end
assign hh_en =((hh_one ==4'd9)&&(hh_ten ==4'd0)&&(mm_one ==4'd9)&&(mm_ten ==4'd5)&& ena &&(ss_one ==4'd9)&&(ss_ten ==4'd5)) ? 1'b1 : 1'b0;
always @(posedge clk) begin
if(reset) begin
hh_ten <=4'b1;
end
else if ((hh_one == 4'd2)&&(hh_ten ==4'd1) && (mm_one == 4'd9)&&(mm_ten ==4'd5) && ena && (ss_one == 4'd9)&&(ss_ten ==4'd5)) begin
hh_ten <= 4'd0;
end
else if(hh_en) begin
hh_ten <=4'd1;
end
end
assign pm_en = ((hh_one == 4'd1)&&(hh_ten ==4'd1) && (mm_one == 4'd9)&&(mm_ten ==4'd5)&& (ss_one == 4'd9)&&(ss_ten ==4'd5) && ena) ? 1'b1 :1'b0;
always @(posedge clk) begin
if (reset) begin
pm <= 1'b0;
end
elseif(pm_en) begin
pm <= ~pm;
end
end
endmodule