module lll(clk,clr,qs,qf,qm,cout,js,jf,jm,en,sel);
input clr,clk,js,jf,jm,en,sel;
output [7:0] qs,qf,qm;
reg [7:0] qs,qf,qm;
reg clkf,clks;
output reg cout;
always @(posedge clk^jm or negedge clr)
begin
if(~clr) qm=1;
else begin
if(en) begin
if(sel) begin
if (qm==0) qm='h59;
else qm=qm+1;
if (qm[3:0]=='hf) begin
qm[3:0]=9; qm[7:4]=qm[7:4]-1;end
if(qm=='h0) clkf=1;
else clkf=0; end
end
end
end
always @(posedge clkf^jf or negedge clr)
begin
if(~clr) qf=1;
else begin
if (qf==0) qf='h59;
else qf=qf-1;
if (qf[3:0]=='hf) begin
qf[3:0]=9; qf[7:4]=qf[7:4]-1;end
if(qf=='h0) clks=1;
else clks=0;end
end
always @(posedge clks^js or negedge clr)
begin
if(~clr) qs=1;
else begin
if (qs==0) qs='h23;
else qs=qs+1;
if (qs[3:0]=='hf) begin
qs[3:0]=9; qs[7:4]=qs[7:4];end
if(qm=='h00) begin
if(qf=='h00)
if(qs=='h00) cout=1;end
else cout=0; end
end
//减法
else begin
always @(posedge clk^jm or negedge clr)
begin
if(~clr) qm=1;
else begin
if(en) begin
if (qm=='h59) qm=0;
else qm=qm+1;
if (qm[3:0]=='ha) begin
qm[3:0]=0; qm[7:4]=qm[7:4]+1;end
if(qm=='h0) clkf=1;
else clkf=0; end
end
end
always @(posedge clkf^jf or negedge clr)
begin
if(~clr) qf=1;
else begin
if (qf=='h59) qf=0;
else qf=qf+1;
if (qf[3:0]=='ha) begin
qf[3:0]=0; qf[7:4]=qf[7:4]+1;end
if(qf=='h0) clks=1;
else clks=0;end
end
always @(posedge clks^js or negedge clr)
begin
if(~clr) qs=1;
else begin
if (qs=='h23) qs=0;
else qs=qs+1;
if (qs[3:0]=='ha) begin
qs[3:0]=0; qs[7:4]=qs[7:4];end
if(qm=='h59) begin
if(qf=='h59)
if(qs=='h23) cout=1;end
else cout=0; end
end
endmodule |