//=========================================================
// SD工作室 Verilog 教學eBOOK (Taiwan Version:01)
//---------------------------------------------------------
// 網址: http://sanddservice.no-ip.org/
//---------------------------------------------------------
//  Module Name: mux4_1_example01_SD.v
// 範例:4X1 Multiplexor [範例01]
// 目的:1.認識4X1 Multiplexor FPGA硬體電路工作原理
//      2.認識Verilog HDL行為模型的parameter敘述編寫應用
//=========================================================

// 4 data inputs, and 2 output.  Select inputs determine
// which data input passes through to the output

// Truth table for 4x1 MUX
// S1  S0  | Data_out
// --------+-------
//  0   0  | input0
//  0   1  | input1
//  1   0  | input2
//  1   1  | input3

`timescale 1ns / 1ps

module mux4_1_example01_SD(Input0, Input1, Input2, Input3, Sel, Data_out);

   input [3:0] Input0;
   input [3:0] Input1;
   input [3:0] Input2;  
   input [3:0] Input3;
   input [1:0] Sel;
   output [3:0] Data_out;
   reg [3:0] Data_out;
  
  
   /*parameter 敘述可用於定義一個常數供模組用來
     定義輸出入埠的寬度、向量的大小等
     語法:parameter name = number;
   */
   // constant declaration
   parameter SelectInput00 = 2'b00;   // 語法:<size>’<base><number>
   parameter SelectInput01 = 2'b01;   // 2b'xx 表所使用2bit數,二進位表示法
   parameter SelectInput02 = 2'b10;
   parameter SelectInput03 = 2'b11;

   always @ (Sel or Input0 or Input1 or Input2 or Input3)
   begin
      case(Sel)
         SelectInput00: begin        //S1 = 0 ; S0 = 0
            Data_out <= Input0;
         end
         SelectInput01: begin        //S1 = 0 ; S0 = 1
            Data_out <= Input1;
         end
         SelectInput02: begin        //S1 = 1 ; S0 = 0
            Data_out <= Input2;
         end
         SelectInput03: begin        //S1 = 1 ; S0 = 1
            Data_out <= Input3;
         end
      endcase
   end
endmodule

//======================================================

arrow
arrow
    文章標籤
    Verilog HDL行為模型的parameter
    全站熱搜
    創作者介紹
    創作者 ysy168twIQ 的頭像
    ysy168twIQ

    ysy168twIQ的部落格

    ysy168twIQ 發表在 痞客邦 留言(0) 人氣()