使用verilog實現4選1數據選擇器的幾種方法


第一種方法
module mux(
d1,
d2,
d3,
d4,
se1,
se2,
dout
);
input d1;
input d2;
input d3;
input d4;
input se1;
input se2;

output dout;

reg dout;

always @ (d1 or d2 or d3 or d4 or se1 or se2)
case({se1,se2})
2'b00 : dout=d1;
2'b01 : dout=d2;
2'b10 : dout=d3;
2'b11 : dout=d4;
endcase
endmodule
第二種方法
module mux(
d1,
d2,
d3,
d4,
se1,
se2,
dout
);
input d1;
input d2;
input d3;
input d4;
input se1;
input se2;

output dout;

reg dout;

always @ (d1 or d2 or d3 or d4 or se1 or se2)
if (!se1)
begin
if (!se2)
dout = d1;
else
dout = d2;
end
else begin
if (!se2)
dout = d3;
else
dout = d4;
end

endmodule
第三種方法
module se(
d1,
d2,
d3,
d4,
se1,
se2,
dout
);
input d1;
input d2;
input d3;
input d4;
input se1;
input se2;

output dout;

reg dout;

always @ (d1 or d2 or d3 or d4 or se1 or se2)
assign dout=se1?se2?d4:d3:se2?d2:d1;
endmodule


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM