2012年10月27日 星期六

P6-29 1x4 DeMUX 適用於DE2-70

P6-29 1x4 DeMUX 適用於DE2-70

//-------------------------------------------------------
//4-bit demultiplexer with if...else if...else if...else...
//Filenale : demux_1x4
//-------------------------------------------------------
module demux_1x4(SW, LEDR, LEDG , CLOCK_27 ,KEY );

input  [17:0] SW; // toggle switches
input  [7:0] KEY;     // Push bottom
input  CLOCK_27; //Clock 27MHz , 50Mhz
output [17:0] LEDR; // red  LEDS   
  output [7:0] LEDG; // green LEDs
  
  
//set original program input , output 

    // Port Declarations

//(y, I, S0, S1);
//output [3:0] y;
//input I;
//input S0, S1;    //Selection signals
    
    
    reg  [3:0] y;
    wire I ,S1,S0;
    
    
    //mapping to hardware 
    assign LEDR = SW;
    
    assign I=SW[0]; 
    assign S1=SW[17];
    assign S0=SW[16];

always @ (I or S0 or S1)
begin
if (S1==1'b0)
begin
if (S0==1'b0)
y = {3'b000, I};   //marge 000 with I to y
else
y = {2'b00, I, 1'b0};
end
else
begin 
if (S0==1'b0)
y = {1'b0, I, 2'b00};
else
y = {I, 3'b000};
end
end
assign LEDG[3:0]=y;
endmodule



沒有留言:

張貼留言

WOKWI DHT22 & LED , Node-Red + SQLite database

 WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...