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

沒有留言:

張貼留言

習題解答 (5/6)

  第五章 習題解答 一、 錯誤偵測技術 1. 何謂循環冗餘檢查法 (CRC)? 是一種根據傳輸資料產生簡短固定位數校驗碼的演算法。發送端將資料除以一個特定的多項式,得到的「餘數」即為 CRC 碼並隨資料發送;接收端以同樣多項式除之,若餘數為 0 則代表資料傳輸正確。 2. 何...