文档详情

Verilog135个经典设计实例.pdf

发布:2017-11-30约10.18万字共83页下载文档
文本预览下载声明
王金明:《Verilog HDL 程序设计教程》 【例3.1】4 位全加器 module adder4(cout,sum,ina,inb,cin); output [3:0] sum; output cout; input [3:0] ina,inb; input cin; assign {cout,sum}=ina+inb+cin; endmodule 【例3.2】4 位计数器 module count4(out,reset,clk); output [3:0] out; input reset,clk; reg [3:0] out; always @(posedge clk) begin if (reset) out=0; //同步复位 else out=out+1; //计数 end endmodule 【例3.3 】4 位全加器的仿真程序 `timescale 1ns/1ns `include adder4.v module adder_tp; //测试模块的名字 reg [3:0] a,b; //测试输入信号定义为reg 型 reg cin; wire [3:0] sum; //测试输出信号定义为wire 型 wire cout; integer i,j; adder4 adder(sum,cout,a,b,cin); //调用测试对象 always #5 cin=~cin; //设定cin 的取值 initial begin a=0;b=0;cin=0; for (i=1;i16;i=i+1) #10 a=i; //设定a 的取值 end - 1 - 程序文本 initial begin for (j=1;j16;j=j+1) #10 b=j; //设定b 的取值 end initial //定义结果显示格式 begin $monitor($time,,,%d + %d + %b={%b,%d},a,b,cin,cout,sum); #160 $finish; end endmodule 【例3.4 】4 位计数器的仿真程序 `timescale 1ns/1ns `include count4.v module coun4_tp; reg clk,reset; //测试输入信号定义为reg 型 wire [3:0] out; //测试输出信号定义为wire 型 parameter DELY=100; count4 mycount(out,reset,clk); //调用测试对象 always #(DELY/2) clk = ~clk; //产生时钟波形 initial begin //激励信号定义 clk =0; reset=0; #DELY reset=1; #DELY reset=0; #(DELY*20) $finish; end //定义结果显示格式 initial $monitor($time,,,clk=%d reset=%d out=%d, clk, reset,out); endmodule 【例3.5 】
显示全部
相似文档