FPGA 模块 按键消抖

本模块主要实现的是按键消抖的功能
高->低 低->高
延时40ms

module key_delay(
	input clk,
	input kin,
	output reg kout
);

reg[31:0] hcnt,lcnt;	//持续时间计数器
parameter  [31:0]  del = 5000000;	
// 延时时间 = 1/clk*del 一般40ms

always @(posedge clk)
begin
	if(!kin)
		lcnt<=lcnt+1'b1;
	else 
		lcnt<=4'b0000;
end

always @(posedge clk)
begin
	if(kin)
		hcnt<=hcnt+1'b1;
	else 
		hcnt<=4'b0000;
end

always @(posedge clk)
begin
	if(hcnt > del)
		kout<=1'b1;
	else if(lcnt > del)
		kout=1'b0;
end

endmodule 


猜你喜欢

转载自blog.csdn.net/Harry_CHL/article/details/120431163