Verilog编程

一、门电路

1.与门

代码

module top_module( 
    input a, 
    input b, 
    output out );
	assign out=a&b;
endmodule

仿真结果

2.非门

代码

module top_module( input in, output out );
	assign out=~in;
endmodule

仿真结果

3.或非门

代码

module top_module( 
    input a, 
    input b, 
    output out );
	assign out=~(a|b);
endmodule

仿真结果

二、组合电路

1.7420芯片

代码

module top_module ( 
    input p1a, p1b, p1c, p1d,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );
    assign p1y=!(p1a&&p1b&&p1c&&p1d);
    assign p2y=!(p2a&&p2b&&p2c&&p2d);
endmodule

仿真结果

2.二对一多路复用器

代码

module top_module( 
    input a, b, sel,
    output out ); 
assign out=sel?b:a;
endmodule

仿真结果

3.半加器

代码

module top_module( 
    input a, b,
    output cout, sum );
	assign cout=a&b;
    assign sum=a^b;
endmodule

三、时序电路

1.D触发器

代码

module top_module (
    input clk,    // Clocks are used in sequential circuits
    input d,
    output reg q );//

    // Use a clocked always block
    //   copy d to q at every positive edge of clk
    //   Clocked always blocks should use non-blocking assignments
    always @(posedge clk)
        begin
            q<=d;
        end
endmodule

仿真结果

2.同步复位D触发器

代码

module top_module (
    input clk,
    input reset,            // Synchronous reset
    input [7:0] d,
    output [7:0] q
);
    always @(posedge clk)
        begin
            if(reset)
                q=0;
            else
                q<=d;
        end
endmodule

仿真结果

四、Robei安装

参考此教程https://blog.csdn.net/Ninquelote/article/details/104906293

原文地址:https://www.cnblogs.com/Zzxin/p/14711073.html