surenyi
4 years ago
3 changed files with 22 additions and 27 deletions
@ -1,22 +1,19 @@ |
|||||
|
module key_delay #(parameter debound = 30) ( |
||||
module key_delay( |
input keypin ,// switch pin |
||||
keypin,//switch pin |
input clk_1K ,// 1ms period |
||||
clk_1K,//50MHZ |
output reg keyout // if key on out 1 |
||||
keyout//if key on out 0 |
|
||||
); |
); |
||||
input keypin; |
reg [9:0] keystate = 0; |
||||
input clk_1K; |
|
||||
output reg keyout; |
|
||||
|
|
||||
reg [20:0] keystate=0; |
|
||||
|
|
||||
always @(posedge clk_1K) |
always @(posedge clk_1K) |
||||
if (keypin==0) keystate=keystate+1'b1; |
if (!keypin) |
||||
else keystate=0; |
keystate = keystate + 1'b1; |
||||
|
else |
||||
always @(posedge clk_1K) |
keystate = 0; |
||||
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) |
||||
endmodule |
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