完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
矩阵键盘状态转移图都对,但是跳转到scan_col0这个后就不会往下跳转,所以按键只有第一列有反应,其他的几列都不会有反应,实在找不出问题在哪里恳请帮助
//状态机第一部分 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 |
|
相关推荐
2个回答
|
|
只有第一列的按键才有反应,其他列的都没反应
|
|
|
|
请使用插入代码功能将完整代码上传便于仿真定位问题。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1533 浏览 1 评论
1313 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
1523 浏览 0 评论
925 浏览 0 评论
2317 浏览 0 评论
1463 浏览 35 评论
5672 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 17:03 , Processed in 0.619967 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号