//-------------------------------------------------------
//4-bit multiplexer with if...else if...else if...else...
//Filenale : mul4_1_if
//-------------------------------------------------------
module mux_4x1(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, s, i);
//output y;
//input [1:0] s; //Select line
//input [3:0] i; //Input data
wire [3:0] i;
wire [1:0] s;
reg y;
//mapping to hardware
assign LEDR = SW;
assign i=SW[3:0];
assign s=SW[17:16];
always @ (s or i)
begin
if (s==2'b00)
y = i[0];
else if (s==2'b01)
y = i[1];
else if (s==2'b10)
y = i[2];
else
y = i[3];
end
assign LEDG[0]=y;
endmodule
沒有留言:
張貼留言