|
|
|
@ -151,9 +151,10 @@ always @(posedge sys_clk or negedge sys_rst) begin
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
reg [4:0] click_time; // max: 20
|
|
|
|
|
reg is_down; // 消抖之后的按键状态, 是一个稳定的状态
|
|
|
|
|
always @(posedge sys_clk or negedge sys_rst) begin
|
|
|
|
|
if (sys_rst == 1'b0) begin
|
|
|
|
|
is_show <= 1'b0;
|
|
|
|
|
is_down <= 1'b0;
|
|
|
|
|
click_time <= 5'd0;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -163,12 +164,8 @@ always @(posedge sys_clk or negedge sys_rst) begin
|
|
|
|
|
else begin
|
|
|
|
|
// 如果一直相同持续时间达到20个时钟周期
|
|
|
|
|
if (click_time == (5'd20 - 5'd1)) begin
|
|
|
|
|
// 当前的key就是可用的
|
|
|
|
|
if (key_1) begin
|
|
|
|
|
is_show <= !is_show;
|
|
|
|
|
end
|
|
|
|
|
else begin
|
|
|
|
|
end
|
|
|
|
|
// 当前的key就是可用的, 返回到外部也就是 is_down
|
|
|
|
|
is_down <= key_1;
|
|
|
|
|
end
|
|
|
|
|
else begin
|
|
|
|
|
click_time <= click_time + 5'd1;
|
|
|
|
@ -177,6 +174,32 @@ always @(posedge sys_clk or negedge sys_rst) begin
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查稳定之后的按键是否按下了
|
|
|
|
|
wire is_click;
|
|
|
|
|
reg is_down_1;
|
|
|
|
|
reg is_down_2;
|
|
|
|
|
assign is_click = is_down_1 && !is_down_2;
|
|
|
|
|
always @(posedge sys_clk or negedge sys_rst) begin
|
|
|
|
|
if (sys_rst == 1'b0) begin
|
|
|
|
|
is_down_1 <= 1'b0;
|
|
|
|
|
is_down_2 <= 1'b0;
|
|
|
|
|
end
|
|
|
|
|
else begin
|
|
|
|
|
is_down_1 <= is_down;
|
|
|
|
|
is_down_2 <= is_down_1;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
always @(posedge sys_clk or negedge sys_rst) begin
|
|
|
|
|
if (sys_rst == 1'b0) begin
|
|
|
|
|
is_show <= 1'b0;
|
|
|
|
|
end
|
|
|
|
|
else if (is_click) begin
|
|
|
|
|
is_show <= !is_show;
|
|
|
|
|
end
|
|
|
|
|
else begin
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
lm u_lm(
|
|
|
|
|
.x (x),
|
|
|
|
|