硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3556|回复: 2
收起左侧

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

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107128
QQ
发表于 2013-1-25 15:36:12 | 显示全部楼层 |阅读模式
【例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
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107128
QQ
 楼主| 发表于 2013-1-25 15:54:56 | 显示全部楼层
双四选一数据选择器 74XX153
1.jpg
【例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'b00ut=in1;
2'b01ut=in2;
2'b10ut=in3;
2'b11ut=in4;
defaultut=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[1:0] 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[1:0] 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[3:0] 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
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107128
QQ
 楼主| 发表于 2013-1-25 16:07:54 | 显示全部楼层
八选一数据选择器  74XX151
1.jpg
2.jpg
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[2:0] 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
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-20 00:42 , Processed in 0.240083 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表