首页 新闻 会员 周边 捐助

verilog 矩阵键盘的状态机只有第一列起作用

0
悬赏园豆:200 [待解决问题]

状态机只扫描第一列,后面的几列都不扫描,所以键值也只有第一列的键值,

//状态机第一部分
always @ (posedge clk100 or negedge rst_n)
if(!rst_n)
current_state <= idle;
else
current_state <= next_state;

// 状态机第二部分
always @ (*)begin
if(!rst_n)
next_state = idle;
else
case (current_state)
idle :
if (row != 5'h1F)
next_state = key_jitter1;
else
next_state = idle;
key_jitter1 :
if (row != 5'h1F)
if ( delay_done == 1'b1)
next_state = scan_col0 ;
else
next_state = key_jitter1;
else
next_state = idle;
scan_col0 :
if (row != 5'h1F)
next_state = key_judge;
else
next_state = scan_col1;
scan_col1 :
if (row != 5'h1F)
next_state = key_judge;
else
next_state = scan_col2;
scan_col2 :
if (row != 5'h1F)
next_state = key_judge;
else
next_state = scan_col3;
scan_col3 :
if (row != 5'h1F)
next_state = key_judge;
else
next_state = idle;
key_judge : // 有按键按下,判断是否为特殊按键
if (({col,row} == 9'b1011_11101) || ({col,row} == 9'b1101_11011) || ({col,row} == 9'b1101_11110) || ({col,row} == 9'b1110_11101) || ({col,row} == 9'b0111_11011) || ({col,row} == 9'b0111_11101) || ({col,row} == 9'b1101_01111) || ({col,row} == 9'b1110_01111))
next_state = key_pressed;
else
next_state = key_pressed3;
key_pressed :
if (row != 5'h1F)
next_state = key_read1;
else
next_state = idle;
key_read1 :
if (row != 5'h1F) begin
if (cnt_1s_sig == 1'b0) //按键小于1s,特殊按键单输出
begin next_state = key_read1; end
else
begin next_state = key_read2; end
end
else
next_state = idle;
key_read2 : //特殊按键长按输出
if (row != 5'h1F )
next_state = idle;
else
next_state = key_read2;
key_pressed3 : //普通按键
if (row != 5'h1F )
next_state = key_read3;
else
next_state = idle;
key_read3 : //普通按键输出
if (row == 5'h1F && delay_done == 1'b1)
next_state = idle;
else
next_state = key_read3;
default: next_state = idle;
endcase
end

reg [3:0] col_val;
reg [4:0] row_val;
// 根据次态,给相应寄存器赋值
always @ (posedge clk100 or negedge rst_n)
if (!rst_n)
begin
col <= 4'h0;
end
else
case (next_state)
idle:col<=4'h0;
key_jitter1:begin end
scan_col0: col <= 4'b0111;
scan_col1: col <= 4'b1011;
scan_col2: col <= 4'b1101;
scan_col3: col <= 4'b1110;
key_judge: col <= col;
key_pressed: begin
col_val<=col;
row_val<=row; //锁存键值
end
key_read1: begin end
key_read2: begin end
key_pressed3: begin end
key_read3: begin end
default:;
endcase

问题补充:

键盘扫描只有第一列起到了作用,只会跳到第一列,不会跳到接下去的几列

shiyang3345的主页 shiyang3345 | 初学一级 | 园豆:2
提问于:2020-10-08 15:25
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册