Verilog——与非门

与非门符号:

与非门真值表

与非门电路原理图

与非门Verilog代码:

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

assign          Y=~(A&B); //assign组合逻辑赋值语句
                          //先与后非,与非操作,Verilog位操作

endmodule

测试代码testbench

//-----testbench  of nand_gate
module nand_gate_tb;
reg          aa,bb;
wire         yy;

//异名例化
nand_gate nand_gate(
							.A(aa),
							.B(bb),
							.Y(yy)
							);

initial begin
					aa<=0;bb<=0;//reg型变量赋值用带箭头的等号
	#10     aa<=0;bb<=0;
	#10     aa<=0;bb<=0;
	#10     aa<=0;bb<=0;
	#10     $stop;//调用$stop系统任务

end

endmodule

四位与非门Verilog代码与测试代码

//四位与非门
`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_4bits
module nand_gate_4bits_tb;
reg[3:0]          aa,bb;
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'b0010;bb<=4'b0110;
	#10     aa<=4'b0111;bb<=4'b0100;
	#10     aa<=4'b0000;bb<=4'b1110;
	#10     $stop;

end

电路原理图:

  • 3
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值