eric2013 发表于 2013-1-25 15:36:12

组合逻辑电路(3)-----数据选择器

【例7.6】门级结构描述的2选1MUX
module mux2_1a(out,a,b,sel);
output out;
input a,b,sel;
not (sel_,sel);
and(a1,a,sel_),
(a2,b,sel);
or (out,a1,a2);
endmodule
【例7.7】行为描述的2选1MUX
module mux2_1b(out,a,b,sel);
output out;
input a,b,sel;
reg out;
always @(a or b or sel)
begin
   if(sel)   out = b;
      else    out = a;
end
endmodule
【例7.8】数据流描述的2选1MUX
module MUX2_1c(out,a,b,sel);
output out;
input a,b,sel;
assign out = sel ? b : a;
endmodule

eric2013 发表于 2013-1-25 15:54:56

双四选一数据选择器 74XX153

【例7.1】调用门元件实现的4选1 MUX
module mux4_1a(out,in1,in2,in3,in4,cntrl1,cntrl2);
output out;
input in1,in2,in3,in4,cntrl1,cntrl2;
wire notcntrl1,notcntrl2,w,x,y,z;
not(notcntrl1,cntrl2),
(notcntrl2,cntrl2);
and(w,in1,notcntrl1,notcntrl2),
   (x,in2,notcntrl1,cntrl2),
   (y,in3,cntrl1,notcntrl2),
(z,in4,cntrl1,cntrl2);
or(out,w,x,y,z);
endmodule
【例7.2】用case语句描述的4选1 MUX
module mux4_1b(out,in1,in2,in3,in4,cntrl1,cntrl2);
output out;
input in1,in2,in3,in4,cntrl1,cntrl2;
reg out;
always@(in1 or in2 or in3 or in4 or cntrl1 or cntrl2)
   case({cntrl1,cntrl2})
2'b00:out=in1;
2'b01:out=in2;
2'b10:out=in3;
2'b11:out=in4;
default:out=2'bx;   //特别注意此语句的处理
   endcase
endmodule
【例7.4】数据流方式描述的4选1 MUX
module mux4_1c(out,in1,in2,in3,in4,cntrl1,cntrl2);
output out;
input in1,in2,in3,in4,cntrl1,cntrl2;
assign out=(in1 & ~cntrl1 & ~cntrl2)|(in2 & ~cntrl1 & cntrl2)|
(in3 & cntrl1 & ~cntrl2)|(in4 & cntrl1 & cntrl2);
endmodule
【例7.5】用条件运算符描述的4选1 MUX
module mux4_1d(out,in1,in2,in3,in4,cntrl1,cntrl2);
output out;
input in1,in2,in3,in4,cntrl1,cntrl2;
assign out=cntrl1 ? (cntrl2 ? in4:in3):(cntrl2 ? in2:in1);
endmodule
【例9.11】用if-else语句描述的4选1 MUX
module mux_if(out,in0,in1,in2,in3,sel);
output out;
input in0,in1,in2,in3;
input sel;
reg out;
always @(in0 or in1 or in2 or in3 or sel)
    begin
if(sel==2'b00)         out=in0;
else if(sel==2'b01)    out=in1;
else if(sel==2'b10)    out=in2;
else            out=in3;
    end
endmodule
【例9.12】用case语句描述的4选1 MUX
module mux_case(out,in0,in1,in2,in3,sel);
output out;
input in0,in1,in2,in3;
input sel;
reg out;
always @(in0 or in1 or in2 or in3 or sel)
begin
case(sel)
2'b00: out=in0;
2'b01: out=in1;
2'b10: out=in2;
default: out=in3;
endcase
end
endmodule
【例5.13】用casez描述的数据选择器
module mux_casez(out,a,b,c,d,select);
output out;
input a,b,c,d;
input select;
reg out;
always @(select or a or b or c or d)
    begin
casez(select)
4'b???1: out = a;
4'b??1?: out = b;
4'b?1??: out = c;
4'b1???: out = d;
endcase
    end
endmodule

eric2013 发表于 2013-1-25 16:07:54

八选一数据选择器74XX151


module mux_8(a,g,d0,d1,d2,d3,d4,d5,d6,d7,y);
input d0,d1,d2,d3,d4,d5,d6,d7;            //输入的八组数据
input g;                                       //输入使能端,低电平有效
input a;                              //输入选择端
output y;                                    //数据输出端
reg y;                                        //数据输出寄存器
always@(*)                               //电平触发
begin
    if(g==0)                            //判断使能端是否有效
      y=0;
    else
      case(a)                            //case语句选择
      3'b000:y=d0;
      3'b001:y=d1;
      3'b010:y=d2;
      3'b011:y=d3;
      3'b100:y=d4;
      3'b101:y=d5;
      3'b110:y=d6;
      3'b111:y=d7;
      default:y=0;                  //其他情况下y赋0
      endcase
end
endmodule
页: [1]
查看完整版本: 组合逻辑电路(3)-----数据选择器