实验一 基本门电路

实验目的

熟悉 Vivado 开发环境,掌握设计流程,包括如何用 Verilog 语言设计电
路、仿真、综合、实现与下载。

实验内容

门电路设计:
使用 Verilog HDL 语言的数据流描述方法设计一个数据宽度可在 1~32
之间变化的 2 输入与门 andgate(或门、非门、与非门等基本门电路),利
用仿真来验证设计。并将该与门封装成可变数据宽度参数的 IP 核。

代码如下
and_notgate.xpr
`timescale 1ns / 1ps

module and_notgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=~(a&b);
endmodule

仿真文件:
and_notgate_sim2

`timescale 1ns / 1ps

module and_notgate_sim2( );
//input
    reg a=0;
    reg b=0;
    
//output
    wire c;
    and_notgate #(1) u(a,b,c);
     
    initial begin
    #100 a=1;
    #100 begin a=0; b=1;end
    #100 a=1;
    end

endmodule

仿真波形图:
在这里插入图片描述

andgate.xpr
`timescale 1ns / 1ps

module andgate #(parameter WIDTH=8)    //指定数据宽度参数,缺省值是8
(
    input [(WIDTH-1):0]a,              //出具位数由参数WIDTH决定
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=a&b;                     //2输入与门
endmodule

仿真文件:
andgate_sim2

`timescale 1ns / 1ps

module andgate_sim2( );
//input
    reg a=0;
    reg b=0;

 //output
    wire c;
    andgate #(1) u(a,b,c);   //实例化与门的时候,设定宽度为1
    
    initial begin
    #100 a=1;
    #100 begin a=0;b=1;end
    #100 a=1;
    end
endmodule

仿真波形图:
在这里插入图片描述

notgate.xpr
`timescale 1ns / 1ps

module notgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    output [(WIDTH-1):0]b
    );
    
    assign b=~a;
endmodule

仿真文件:
notgate_sim2

`timescale 1ns / 1ps

module notgate_sim2( );
//input
    reg a=0;

 //output
    wire b;
    notgate #(1) u(a,b);   //实例化非门的时候,设定宽度为1
    
    initial begin
    #100 a=1;
    #100 begin a=0;end
    #100 a=1;
    end
endmodule

仿真波形图:
在这里插入图片描述

nxorgate.xpr
`timescale 1ns / 1ps

module nxorgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=~(a^b);
endmodule

仿真文件:
nxorgate_sim2

`timescale 1ns / 1ps

module nxorgate_sim2( );
//input
    reg a=0;
    reg b=0;
    
//output
    wire c;
    nxorgate #(1) u(a,b,c);        //传入参数为1,设置宽度WIDTH=1
     
    initial begin
    #100 a=1;
    #100 begin a=0; b=1;end
    #100 a=1;
    end

endmodule

仿真波形图:
在这里插入图片描述

or_notgate.xpr
`timescale 1ns / 1ps

module or_notgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=~(a|b);
endmodule

仿真文件:
or_notgate_sim2

`timescale 1ns / 1ps

module or_notgate_sim2( );
//input
    reg a=0;
    reg b=0;
    
//output
    wire c;
    or_notgate #(1) u(a,b,c);
     
    initial begin
    #100 a=1;
    #100 begin a=0; b=1;end
    #100 a=1;
    end

endmodule

仿真波形图:
在这里插入图片描述

orgate.xpr
`timescale 1ns / 1ps

module orgate #(parameter WIDTH=8)    //指定数据宽度参数,缺省值是8
(
    input [(WIDTH-1):0]a,              //出具位数由参数WIDTH决定
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=a|b;                     //2输入或门
endmodule

仿真文件:
orgate_sim

`timescale 1ns / 1ps

module orgate_sim( );
    reg [31:0]a=32'h00000000;
    reg [31:0]b=32'h00000000;
    
    wire [31:0]c;
    orgate #(32) u(a,b,c);
    
    initial begin
    #100 a=32'hffffffff;
    #100 begin a=32'h00000000;b=32'hffffffff;end
    #100 a=32'h007fa509;
    #100 a=32'hffffffff;
    end
endmodule

仿真波形图:
在这里插入图片描述

xorgate.xpr
`timescale 1ns / 1ps

module xorgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=a^b;
endmodule

仿真文件:
xorgate_sim2

`timescale 1ns / 1ps

module xorgate_sim2( );
//input
    reg a=0;
    reg b=0;
    
//output
    wire c;
    xorgate #(1) u(a,b,c);        //传入参数为1,设置宽度WIDTH=1
     
    initial begin
    #100 a=1;
    #100 begin a=0; b=1;end
    #100 a=1;
    end

endmodule

仿真波形图:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

罗娜mei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值