module debounce(clk,key_in,key_out); //按键消抖模块
input clk; //系统时钟输入
input[KEY_WIDTH-1:0] key_in; //外部按键输入
output[KEY_WIDTH-1:0]key_out; //按键消抖输出
reg[KEY_WIDTH-1:0]dout1,dout2,dout3; //寄存器
parameter KEY_WIDTH = 8; //参数
assign key_out = (dout1 | dout2 | dout3); //按键消抖输出
always @(posedge clk)
begin
dout1 <= key_in;
dout2 <= dout1;
dout3 <= dout2;
end
endmodule
input clk; //系统时钟输入
input[KEY_WIDTH-1:0] key_in; //外部按键输入
output[KEY_WIDTH-1:0]key_out; //按键消抖输出
reg[KEY_WIDTH-1:0]dout1,dout2,dout3; //寄存器
parameter KEY_WIDTH = 8; //参数
assign key_out = (dout1 | dout2 | dout3); //按键消抖输出
always @(posedge clk)
begin
dout1 <= key_in;
dout2 <= dout1;
dout3 <= dout2;
end
endmodule