3、0: o_ut_st <= 4'b0010; 2'b11: o_ut_st <= 4'b0001; endcase end//根据按钮的列扫描信号和行输入信号判断按钮是否被按下always @(posedge clk) begin //如果无按钮按下,定义num=16为无效状态 if (in_s == 4'b0000) begin if (tmp == 3) begin
4、 num <= 16; //无按键输入,输出16 tmp <= 0; end else begin num <= num; tmp <= tmp + 1'b1; //扫描周期,3个时钟周期 end end else begin tmp <= 0; case
5、(dsample) //第1列扫描结果 8'b1000_0001: num <= 0; 8'b1000_0010: num <= 1; 8'b1000_0100: num <= 2; 8'b1000_1000: num <= 3; //第2列扫描结果 8'b0100_0001: num <= 4; 8'b0100_0010: num <= 5
6、; 8'b0100_0100: num <= 6; 8'b0100_1000: num <= 7; //第3列扫描结果 8'b0010_0001: num <= 8; 8'b0010_0010: num <= 9; 8'b0010_0100: num <= 10; 8'b0010_1000: num <= 11; //第4列扫描结果
7、 8'b0001_0001: num <= 12; 8'b0001_0010: num <= 13; 8'b0001_0100: num <= 14; 8'b0001_1000: num <= 15; endcase end endendmodule 独立按键消抖程序:module Btn_without_shake(Clk_50MHz,PB_UP,PB_Out,count_sel);//定义模块