surenyi
4 years ago
3 changed files with 22 additions and 27 deletions
@ -1,22 +1,19 @@ |
|||
|
|||
module key_delay( |
|||
keypin,//switch pin |
|||
clk_1K,//50MHZ |
|||
keyout//if key on out 0 |
|||
module key_delay #(parameter debound = 30) ( |
|||
input keypin ,// switch pin |
|||
input clk_1K ,// 1ms period |
|||
output reg keyout // if key on out 1 |
|||
); |
|||
input keypin; |
|||
input clk_1K; |
|||
output reg keyout; |
|||
|
|||
reg [20:0] keystate=0; |
|||
reg [9:0] keystate = 0; |
|||
|
|||
always @(posedge clk_1K) |
|||
if (keypin==0) keystate=keystate+1'b1; |
|||
else keystate=0; |
|||
|
|||
always @(posedge clk_1K) |
|||
if(keystate>=30) keyout=0; // 30ms key on ,if have 30 times 1 ,can ensure key on ,and output 0 |
|||
else keyout=1; |
|||
always @(posedge clk_1K) |
|||
if (!keypin) |
|||
keystate = keystate + 1'b1; |
|||
else |
|||
keystate = 0; |
|||
|
|||
|
|||
endmodule |
|||
always @(posedge clk_1K) |
|||
if (keystate >= debound) |
|||
keyout = 1; // default 30ms key on, if have 30 times 1, can ensure key on, and output 1 |
|||
else |
|||
keyout = 0; |
|||
endmodule |
|||
|
Loading…
Reference in new issue