源自於 https://www.rfwireless-world.com/source-code/VERILOG/2-to-4-decoder-verilog-code.html
module decoder_2x4_enable(a,b,en,y);
input a, b, en;
output [3:0]y;
assign y[0]= (~a) & (~b) & en;
assign y[1]= (~a) & b & en;
assign y[2]= a & (~ b) & en;
assign y[3]= a & b & en;
endmodule
// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps
module Test_bench;
reg tA = 1'b0; // A 暫存器資料初值為‘0’
reg tB = 1'b0; // B 暫存器資料初值為‘0’
reg tEN = 1'b1;
wire [3:0]tY;
//decoder_2x4_enable(a,b,en,y);
decoder_2x4_enable DUT(.a(tA),.b(tB),.en(tEN),.y(tY));
// initial程序結構區塊, 產生A、B輸入信號波形
initial
begin
#100; tA = 1'b1;tB = 1'b0; // “10”
#100; tA = 1'b0;tB = 1'b1; // “01”
#100; tA = 1'b1;tB = 1'b1; // “11”
#100; tEN = 1'b0; tA = 1'b1;tB = 1'b1; // “11”
#100; tA = 1'b1;tB = 1'b0; // “10”
#100; tA = 1'b0;tB = 1'b1; // “01”
end
initial
begin
#800; // 模擬終止時間 400 ns
$stop;
end
endmodule
沒有留言:
張貼留言