always@(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)
begin
cnt <= 25'd0;
end
else
begin
if(cnt < CNT_MAX -25'd1)
begin
cnt <= cnt +25'd1;
end
else
begin
cnt <= 25'd0;
end
end
end
reg Touch_Key_d0;
reg Touch_Key_d1;
wire Touch_Key_en; // touch valid
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n) begin
Touch_Key_d0 <= 1'b0;
Touch_Key_d1 <= 1'b0;
end
else begin
Touch_Key_d0 <= Touch_Key;
Touch_Key_d1 <= Touch_Key_d0;
end
end
assign Touch_Key_en = (~Touch_Key_d1)&Touch_Key_d0;
reg flag_Led;
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n) begin
flag_Led <= 1'b1;
end
else if(Touch_Key_en)
flag_Led <= ~flag_Led;
end
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n) begin
Led <= 4'b1000;
end
else if(flag_Led && (cnt == CNT_MAX -25'd1))
Led <= {Led[2:0],Led[3]};
else
Led <= Led;
end
endmodule触摸按键控制LED流水,理论上应该是上板后呈现流水效果,触摸一次暂停,在触摸恢复, 我看QuestaSIM 波形吻合,但是实际上板 需要手动复位(或者触摸一下)之后才开始流水, 看不出代码有什么问题,请各位佬指点