verilog的秒表设计代码
防抖模块: module button_scan(clk, bin, bout); input clk; input bin; output bout; reg bout; parameter cnt = 200; reg [ 1: 0] state = 0; reg [31: 0] dcnt; always@(posedge clk) case(state) 0: begin //不稳定0 if(bin) state <= 1; else state <= dcnt>=dcnt?2:0; end 1: begin //稳定1 if(!bin) begin state <= 0; dcnt <= 0; end end 2: begin //稳定0 if(bin) begin state <= 3; dcnt <= 0; end end 3: begin //不稳定1 if(!bin) state <= 2; else state <= dcnt>=dcnt?1:3; end endcase always@(state) case(state) 0: bout <= bout; 1: bout <= 1; 2: bout <= 0; 3: bout <= bout; default: bout <= bout; endcase endmodule
|