2020年1月4日 星期六

2 to 4 decoder HDL Verilog Code

2 to 4 decoder HDL Verilog Code

源自於 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

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...