|
楼主 |
发表于 2018-9-18 22:43:49
|
显示全部楼层
module Decoder3_8(
A,
y
);
input [2:0] A;
output [7:0] y;
reg [7:0] y_reg;
always @ (*)begin
case(A[2:0])
3'b000: y_reg = 8'b1111_1110;
3'b001: y_reg = 8'b1111_1101;
3'b010: y_reg = 8'b1111_1011;
3'b011: y_reg = 8'b1111_0111;
3'b100: y_reg = 8'b1110_1111;
3'b101: y_reg = 8'b1101_1111;
3'b110: y_reg = 8'b1011_1111;
3'b111: y_reg = 8'b1111_1111;
3'bxxx: y_reg = 8'b1111_1111;
default: y_reg = 8'b1111_1111;
endcase
end
assign y = y_reg;
endmodule
`timescale 1ns/1ns
`define clock_period 20
module Decoder3_8_tb;
//reg---in
reg [2:0] A;
//wire--out
wire [7:0] y;
//instance
Decoder3_8 Decoder3_8_instance
(
.A(A), //括号里面为上面定义的变量
.y(y)
);
initial begin
A = 3'b000;
#(20*10);
A = 3'b001;
#(20*10);
A = 3'b010;
#(20*10);
A = 3'b011;
#(20*10);
A = 3'b100;
#(20*10);
A = 3'b101;
#(20*10);
A = 3'b110;
#(20*10);
A = 3'b111;
#(20*10);
#(20*100);
$stop;
end
endmodule |
|