1、模块
模块内部的5个组成是:变量声明 数据流语句 低层模块实例 函数和任务 行为语句
SR锁存器
`timescale 1ns / 1ps
module SR_latch
(
input wire Sbar ,
input wire Rbar ,
output wire Q ,
output wire Qbar
);
nand n1(Q,Sbar,Qbar) ;
nand n2(Qbar,Rbar,Q) ;
endmodule
tb_sr
`timescale 1ns / 1ps
module tb();
wire Q,Qbar ;
reg Sbar,Rbar ;
SR_latch m1(Sbar,Rbar,Q,Qbar) ;
initial
begin
$monitor($time,"Sbar = %b Rbar = %b Q = %b",Sbar,Rbar,Q) ;
Sbar = 1'b0 ;
Rbar = 1'b0 ;
#5
Rbar = 1'b1 ;
#5
Rbar = 1'b0 ;
#5
Sbar = 1'b1 ;
end
endmodule
2、端口
端口就是模块与外界环境交互的接口。
2.1、 端口列表
有端口列表的模块
module fulladd4
(
output sum ,
output c_out ,
input a ,
input b ,
input c_in
);
没有端口列表的仿真模块
module tb ;
2.2、 端口申明
|------------|------|
| verilog关键字 | 端口类型 |
| input | 输入 |
| output | 输出 |
| inout | 双向端 |
[端口]
2.3、 端口连接规则
输入端口 必须为 线网数据类型。input可以外界 接 reg 或者 wire。
输出端口 可以为reg或者wire。总体而言 ,输出必须接到线网,不能接到reg。
inout端口 必须为 wire。
verilog 运行位宽不同,但是会给出 warn。
2.4、 端口 与 外部信号的连接
顺序端口连接
命名端口连接
这两种方式不能混用。
3、层次命名
如下,可以用 . 分隔。
stimulus.Qbar.Q