4.Verilog HDL建模描述
程序清单four_in_gates.v
//********************************************************
//
// Copyright(c)2016, STEP FPGA
// All rights reserved
//
// File name : four_in_gates.v
// Module name : four_in_gates
// Author : STEP
// Email : info@stepfpga.com
// Data : 2016/08/19
// Version : V1.0
// Description : 4 inputs and 6 logic four_in_gates
//
// Modification history
// ----------------------------------------------------------------------------
// Version Data(2016/08/19) V1.0
// Description
//
//********************************************************
//
//
//*******************
//DEFINE MODULE PORT
//*******************
module four_in_gates
(
//INPUT
a ,
//OUTPUT
led ,
empty
);
//*******************
//DEFINE INPUT
//*******************
input [3:0] a;
//*******************
//DEFINE OUTPUT
//*******************
output [7:0] empty;
output [5:0] led;
wire [5:0] z;
//Combinational logic style
// assign z[5]=a[0]&a[1]&a[2]&a[3]; //three kinds of AND logic expression
// assign z[5]=&a;
and(z[5],a[0],a[1],a[2],a[3]);
// assign z[4]=~(a[0]&a[1]&a[2]&a[3]); //three kinds of NAND logic expression
// assign z[4]=~&a;
nand(z[4],a[0],a[1],a[2],a[3]);
// assign z[3]=a[0]|a[1]|a[2]|a[3]; //three kinds of OR logic expression
// assign z[3]=|a;
or(z[3],a[0],a[1],a[2],a[3]);
// assign z[2]=~(a[0]|a[1]|a[2]|a[3]); //three kinds of NOR logic expression
// assign z[2]=~|a;
nor(z[2],a[0],a[1],a[2],a[3]);
// assign z[1]=a[0]^a[1]^a[2]^a[3]; //three kinds of XOR logic expression
// assign z[1]=^a;
xor(z[1],a[0],a[1],a[2],a[3]);
// assign z[0]=a[0]~^a[1]~^a[2]~^a[3]; //three kinds of XNOR logic expression
// assign z[0]=~^a;
xnor(z[0],a[0],a[1],a[2],a[3]);
assign led=~z; //led is low active
assign empty=8'b1111_1111; //led's defualt mode is lighted
endmodule
仿真程序清单gates_tb.v
//
//*******************
//DEFINE MODULE PORT
//*******************
`timescale 1ns/100ps
module four_in_gates_tb;
reg [3:0] a;
initial
begin
a[0]=0;
a[1]=0;
a[2]=0;
a[3]=0;
#50;
a[0]=0;
a[1]=0;
a[2]=0;
a[3]=1;
#50;
a[0]=0;
a[1]=0;
a[2]=1;
a[3]=0;
#50;
a[0]=0;
a[1]=0;
a[2]=1;
a[3]=1;
#50;
a[0]=0;
a[1]=1;
a[2]=0;
a[3]=0;
#50;
a[0]=0;
a[1]=1;
a[2]=0;
a[3]=1;
#50;
a[0]=0;
a[1]=1;
a[2]=1;
a[3]=0;
#50;
a[0]=0;
a[1]=1;
a[2]=1;
a[3]=1;
#50;
a[0]=1;
a[1]=0;
a[2]=0;
a[3]=0;
#50;
a[0]=1;
a[1]=0;
a[2]=0;
a[3]=1;
#50;
a[0]=1;
a[1]=0;
a[2]=1;
a[3]=0;
#50;
a[0]=1;
a[1]=0;
a[2]=1;
a[3]=1;
#50;
a[0]=1;
a[1]=1;
a[2]=0;
a[3]=0;
#50;
a[0]=1;
a[1]=1;
a[2]=0;
a[3]=1;
#50;
a[0]=1;
a[1]=1;
a[2]=1;
a[3]=0;
#50;
a[0]=1;
a[1]=1;
a[2]=1;
a[3]=1;
#50;
end
four_in_gates four_in_gates_tb_uut(
.a(a)
);
endmodule |