(1)实现代码:
module decoder3_8
(
input wire key_en ,
input wire A , //S0
input wire B , //S1
input wire C , //S2
output reg [7:0] led_out
);
//观察原理图,可知该开发板的按键按下电平为0,释放电平为1
//该开发板电平为1时led熄灭,电平为0时led点亮
//我想要观察到的现象:释放使能按键时,保持使能为1,按下使能为0;使能条件下,按下S2,S1,S3,led8点亮
wire [2:0] in;
assign in = {~A,~B,~C};
always@(*)begin
if(!key_en)
led_out <= 8'b1111_1111;
else begin
case(in)
3'd0: led_out <= 8'b1111_1110;
3'd1: led_out <= 8'b1111_1101;
3'd2: led_out <= 8'b1111_1011;
3'd3: led_out <= 8'b1111_0111;
3'd4: led_out <= 8'b1110_1111;
3'd5: led_out <= 8'b1101_1111;
3'd6: led_out <= 8'b1011_1111;
3'd7: led_out <= 8'b0111_1111;
default:led_out <= 8'b1111_1111;
endcase
end
end
endmodule
(2)引脚分配:
(3)实验现象:
- 未按下S4,使能拉高,此时按下S2,对应3‘b010,led3点亮;
- 未按下S4,使能拉高,此时按下S1,对应3’d100,led5点亮;
- 未按下S4,使能拉高,此时同时按下S1和S3,对应3’d101,led6点亮;
- 未按下S4,使能拉高,此时同时按下S1、S2和S3,对应3’d111,led8点亮;
- 按下S4,使能拉低,此时无论按什么按键,led灯都不会点亮;