完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
如果现在一共有18个拨动开关,用什么样的办法检测被关闭的两个开关是哪?只要求测出最左和最右两端的开关。我自己的思路部分代码如下:
input[17:0] rang; wire[17:0] rang_1; assign rang_1 ={rang[0], rang[1], rang[2],rang[3],rang[4],rang[5],rang[6],rang[7], rang[8],rang[9], rang[10],rang[11],rang[12],rang[13],rang[14],rang[15],rang[16],rang[17]}; always @(posedge clk or negedge clr_n) if(!clr_n) left_temp <=5'd0; else casex(rang) 18'b1xxxxxxxxxxxxxxxxx:left_temp <= 5'd1; 18'b01xxxxxxxxxxxxxxxx:left_temp <= 5'd2; 18'b001xxxxxxxxxxxxxxx:left_temp <= 5'd3; 18'b0001xxxxxxxxxxxxxx:left_temp <= 5'd4; 18'b00001xxxxxxxxxxxxx:left_temp <= 5'd5; 18'b000001xxxxxxxxxxxx:left_temp <= 5'd6; 18'b0000001xxxxxxxxxxx:left_temp <= 5'd7; 18'b00000001xxxxxxxxxx:left_temp <= 5'd8; 18'b000000001xxxxxxxxx:left_temp <= 5'd9; 18'b0000000001xxxxxxxx:left_temp <= 5'd10; 18'b00000000001xxxxxxx:left_temp <= 5'd11; 18'b000000000001xxxxxx:left_temp <= 5'd12; 18'b0000000000001xxxxx:left_temp <= 5'd13; 18'b00000000000001xxxx:left_temp <= 5'd14; 18'b000000000000001xxx:left_temp <= 5'd15; 18'b0000000000000001xx:left_temp <= 5'd16; 18'b00000000000000001x:left_temp <= 5'd17; 18'b000000000000000001:left_temp <= 5'd18; default: left_temp <= 5'd0; endcase always @(posedge clk or negedge clr_n) if(!clr_n) right_temp <=5'd13; else casex(rang) 18'bxxxxxxxxxxxxxxxxx1:right_temp <= 5'd18; 18'bxxxxxxxxxxxxxxxx10:right_temp <= 5'd17; 18'bxxxxxxxxxxxxxxx100:right_temp <= 5'd16; 18'bxxxxxxxxxxxxxx1000:right_temp <= 5'd15; 18'bxxxxxxxxxxxxx10000:right_temp <= 5'd14; 18'bxxxxxxxxxxxx100000:right_temp <= 5'd13; 18'bxxxxxxxxxxx1000000:right_temp <= 5'd12; 18'bxxxxxxxxxx10000000:right_temp <= 5'd11; 18'bxxxxxxxxx100000000:right_temp <= 5'd10; 18'bxxxxxxxx1000000000:right_temp <= 5'd9; 18'bxxxxxxx10000000000:right_temp <= 5'd8; 18'bxxxxxx100000000000:right_temp <= 5'd7; 18'bxxxxx1000000000000:right_temp <= 5'd6; 18'bxxxx10000000000000:right_temp <= 5'd5; 18'bxxx100000000000000:right_temp <= 5'd4; 18'bxx1000000000000000:right_temp <= 5'd3; 18'bx10000000000000000:right_temp <= 5'd2; 18'b100000000000000000:right_temp <= 5'd1; default: right_temp <= 5'd19; endcase |
|
相关推荐
|
|
用case,类似于c语言里的sW讠tCh
|
|
|
|
|
|
1539 浏览 1 评论
助力AIoT应用:在米尔FPGA开发板上实现Tiny YOLO V4
1077 浏览 0 评论
2619 浏览 1 评论
2306 浏览 0 评论
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
2578 浏览 0 评论
2031 浏览 55 评论
6038 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 03:52 , Processed in 0.425402 second(s), Total 39, Slave 31 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号