题解 | #用优先编码器①实现键盘编码电路#
用优先编码器①实现键盘编码电路
https://www.nowcoder.com/practice/03b8c5837d7f406797b4a57358057ef7
module key_encoder( input [9:0] S_n , output reg [3:0] L , output reg GS ); wire [3:0]out1; encoder_0 encoder_0_inst ( .I_n({S_n[8:0]}), .Y_n (out1) ); always@(*) if (S_n[9] == 1'b0) L <= 4'd9; else if (out1 == 4'b1110) L <= 4'd0; else if (out1 == 4'b1101) L <= 4'd1; else if (out1 == 4'b1100) L <= 4'd2; else if (out1 == 4'b1011) L <= 4'd3; else if (out1 == 4'b1010) L <= 4'd4; else if (out1 == 4'b1001) L <= 4'd5; else if (out1 == 4'b1000) L <= 4'd6; else if (out1 == 4'b0111) L <= 4'd7; else if (out1 == 4'b0110) L <= 4'd8; always@(*) //着GS就很迷茫,但是这样子写是对的,我也不知道是咋碰对的QAQ if (out1 == 4'b1110) GS <= 1'b1; else if (out1 == 4'b1111) GS <= 1'b0; else GS <= 1'b1; endmodule