【1】Verilog练习-基本门电路反相器&与非门
我的学记|刘航宇的博客

【1】Verilog练习-基本门电路反相器&与非门

刘航宇
3年前发布 /正在检测是否收录...
温馨提示:
本文最后更新于2022年05月19日,已超过1045天没有更新,若内容或图片失效,请留言反馈。

反相器

图片[1] - 【1】Verilog练习-基本门电路反相器&与非门 - 我的学记|刘航宇的博客

//反相器设计
`timescale 1ns/10ps  //1ns时间单位,10ps精度
module inv(
        A,
        Y
);
input   A;
output  Y;
assign  Y=~A;
endmodule
//---testbench of inv--
module inv_tb; //testbench无端口不写括号
reg        aa; //输入
wire    yy; //输出
inv  inv(
        .A(aa),
        .Y(yy)
        ); //异名例化
initial begin
        aa<=0;
    #10 aa<=1; //过10个时间单位timescale
    #10 aa<=0;
    #10 aa<=1;
    #10 $stop;    
end
endmodule

现象:
图片[2] - 【1】Verilog练习-基本门电路反相器&与非门 - 我的学记|刘航宇的博客

多位反相器

图片[3] - 【1】Verilog练习-基本门电路反相器&与非门 - 我的学记|刘航宇的博客

与非门

l378lznf.png
代码

//与非门
`timescale 1ns/10ps
module nand_gate(
            A,
            B,
            Y
);
input        A;
input        B;
output        Y;

assign        Y=~(A&B);
endmodule
//------testbench of nand_gate--
module nand_gate_tb;

reg            aa,bb; //输入定义为reg
wire        yy;

nand_gate nand_gate(
                .A(aa),
                .B(bb),
                .Y(yy)
            );
initial begin
                aa<=0;bb<=0; //用箭头等号对应实际电路
        #10     aa<=1;bb<=1;
        #10     aa<=0;bb<=1;
        #10     aa<=1;bb<=0;
        #10     aa<=0;bb<=0;
        #10     $stop;
end
endmodule

现象
l379jg44.png

多位与非门

l379koe9.png
代码

//与非门
`timescale 1ns/10ps
module nand_gate_4bits(
                        A,
                        B,
                        Y
                        );
input[3:0]                A;
input[3:0]                B;
output[3:0]                Y;

assign                    Y=~(A&B);
endmodule
//------testbench of nand_gate--
module nand_gate_4bits_tb;

reg[3:0]                aa,bb; //输入定义为reg
wire[3:0]                yy;

nand_gate_4bits nand_gate_4bits(
                        .A(aa),
                        .B(bb),
                        .Y(yy)
            );
initial begin
                aa<=4'b0000;bb<=4'b1111; //用箭头等号对应实际电路
        #10     aa<=4'b1110;bb<=4'b0011;
        #10     aa<=4'b0110;bb<=4'b0111;
        #10     aa<=4'b0111;bb<=4'b1110;
        #10     aa<=4'b1101;bb<=4'b1111;
        #10     $stop;
end
endmodule

l379uc5u.png

© 版权声明
THE END
喜欢就支持一下吧
点赞 2 分享 赞赏
评论 抢沙发
取消