1。建立以功能文件div.v 和测试文件tdiv.v //div.v module div(clk_i,clk_o,reset); parameter DIV_N = 4; input clk_i; input reset; output clk_o; reg clk_o; integer count;
always @ (negedge reset or posedge clk_i) begin if(!reset) count <= 0; else if (count == 3) count <= 0; else count <= count + 1; end
always @ (negedge reset or posedge clk_i) begin if(!reset) clk_o <= 0; else begin if(count <= (DIV_N/2 - 1)) clk_o <= 0; else clk_o <= 1; end end endmodule
//tdiv.v module testdiv; reg clk_i; reg reset; wire clk_o; always #50 clk_i = ~clk_i; initial begin #0 reset = 0; clk_i = 0; #100 reset = 1; #2000 $stop; end
div div1(.clk_i(clk_i),.clk_o(clk_o),.reset(reset)); endmodule
|