题解 | #优先编码器Ⅰ#
优先编码器Ⅰ
https://www.nowcoder.com/practice/a7068b8f4c824d6a9592f691990b21de
`timescale 1ns/1ns
module encoder_83(
input [7:0] I ,
input EI ,
output wire [2:0] Y ,
output wire GS ,
output wire EO
);
//EI 使能
//GS表示按键是否按下,有按键按下则为1,没有按键按下则为0
//当EI=1时,EO与GS刚好相反
reg [3:0] Y0;
always @(*) begin
if (EI) begin
casex(I)
8'b00000000 : Y0 <= 3'b000;
8'b1xxxxxxx : Y0 <= 3'b111;
8'b01xxxxxx : Y0 <= 3'b110;
8'b001xxxxx : Y0 <= 3'b101;
8'b0001xxxx : Y0 <= 3'b100;
8'b00001xxx : Y0 <= 3'b011;
8'b000001xx : Y0 <= 3'b010;
8'b0000001x : Y0 <= 3'b001;
8'b00000001 : Y0 <= 3'b000;
default : Y0 <= 3'b000;
endcase
end
else begin
Y0 <= 0;
end
end
assign Y = Y0;
assign GS = (I == 8'b00000000 | EI == 0)?0 : 1;
assign EO = (I == 8'b00000000)?1 : 0;
endmodule
