题解 | #实现3-8译码器①#

实现3-8译码器①

https://www.nowcoder.com/practice/89659f98cb124362b1c816f06d5235d0

`timescale 1ns/1ns

module decoder_38(
   input             E1_n   ,
   input             E2_n   ,
   input             E3     ,
   input             A0     ,
   input             A1     ,
   input             A2     ,
   
   output wire       Y0_n   ,  
   output wire       Y1_n   , 
   output wire       Y2_n   , 
   output wire       Y3_n   , 
   output wire       Y4_n   , 
   output wire       Y5_n   , 
   output wire       Y6_n   , 
   output wire       Y7_n   
);

reg Y0;
reg Y1;
reg Y2;
reg Y3;
reg Y4;
reg Y5;
reg Y6;
reg Y7;
always@(*)begin 
    casez({E3,E2_n,E1_n,A2,A1,A0})
    6'b?_1_?_???:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1111_1111;
    6'b?_?_1_???:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1111_1111;
    6'b0_?_?_???:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1111_1111;
    6'b1_0_0_000:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b0111_1111;

    6'b1_0_0_001:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1011_1111;
    6'b1_0_0_010:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1101_1111;
    6'b1_0_0_011:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1110_1111;
    6'b1_0_0_100:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1111_0111;
    
    6'b1_0_0_101:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1111_1011;
    6'b1_0_0_110:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1111_1101;
    6'b1_0_0_111:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1111_1110;
    default:{Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7} = 8'b1111_1111;
    endcase
end

assign Y0_n = Y0;
assign Y1_n = Y1;
assign Y2_n = Y2;
assign Y3_n = Y3;
assign Y4_n = Y4;
assign Y5_n = Y5;
assign Y6_n = Y6;
assign Y7_n = Y7;


endmodule

对照真值表使用casez语句即可。

全部评论

相关推荐

点赞 评论 收藏
分享
已老实求offer😫:有点像徐坤(没有冒犯的意思哈)
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务