不需要每一接腳KEY 了老半天,寫成的Verilog 程式 (Download DE2-70 Test OK )
assign X = SW[7:0]; //input x
assign Y = SW[15:8]; //input y
assign sel = SW[17]; //sel
assign s0 = ~sel; //sel_bar (inverter)
// Implements eight 2-to-1 multiplexers.
// inputs: SW7-0 represent the 8-bit input X, and SW15-8 represent Y
// SW17 selects either X or Y to drive the output LEDs
// outputs: LEDR17-0 show the states of the switches
// LEDG7-0 shows the outputs of the multiplexers
module mux2x1_8 (SW, LEDR, LEDG);
input [17:0] SW; // toggle switches
output [17:0] LEDR; // red LEDs
output [7:0] LEDG; // green LEDs
wire sel;
wire [7:0] X, Y, M;
//**********
wire [7:0] sa ,sb;
wire s0;
assign LEDR = SW;
assign X = SW[7:0];
assign Y = SW[15:8];
assign sel = SW[17];
assign s0 = ~sel;
//gate instantitions
and(sa[0],X[0],s0);
and(sb[0],Y[0],sel);
or(M[0],sa[0],sb[0]);
and(sa[1],X[1],s0);
and(sb[1],Y[1],sel);
or(M[1],sa[1],sb[1]);
and(sa[2],X[2],s0);
and(sb[2],Y[2],sel);
or(M[2],sa[2],sb[2]);
and(sa[3],X[3],s0);
and(sb[3],Y[3],sel);
or(M[3],sa[3],sb[3]);
and(sa[4],X[4],s0);
and(sb[4],Y[4],sel);
or(M[4],sa[4],sb[4]);
and(sa[5],X[5],s0);
and(sb[5],Y[5],sel);
or(M[5],sa[5],sb[5]);
and(sa[6],X[6],s0);
and(sb[6],Y[6],sel);
or(M[6],sa[6],sb[6]);
and(sa[7],X[7],s0);
and(sb[7],Y[7],sel);
or(M[7],sa[7],sb[7]);
assign LEDG[7:0] = M;
endmodule
沒有留言:
張貼留言