1 //单个LED灯以一秒闪烁的源代码
2 //利用单个的闪烁源代码,来实例化不同频率闪烁的灯
3 module led_run8(
4 clk,
5 reset_n,
6 led
7 );
8 input clk;
9 input reset_n;
10 output reg led;
11 reg [24:0] counter;
12 parameter MCNT=24999999;
13 always@(posedge clk or negedge reset_n)
14 if(!reset_n)
15 counter<=0;
16 else if(counter==MCNT)
17 counter<=0;
18 else
19 counter<=counter+1'b1;
20 always@(posedge clk or negedge reset_n)
21 if(!reset_n)
22 led<=0;
23 else if(counter==MCNT)
24 led<=!led;
25 endmodule
26 //例化实现不同频率的代码
27 module led_run8_test(
28 clk,
29 reset_n,
30 led
31 );
32 input clk;
33 input reset_n;
34 output wire [3:0] led;//这边相当于输出一定要用wire或者什么也不用标注
35
36 led_run8 led_run8_test0(
37 .clk(clk),
38 .reset_n(reset_n),
39 .led(led[0])
40 );
41 defparam led_run8_test0.MCNT=2499999;//通过程序员计数器算得到
42
43 led_run8 led_run8_test1(
44 .clk(clk),
45 .reset_n(reset_n),
46 .led(led[1])
47 );
48 defparam led_run8_test1.MCNT=4999999;
49
50 led_run8 led_run8_test2(
51 .clk(clk),
52 .reset_n(reset_n),
53 .led(led[2])
54 );
55 defparam led_run8_test2.MCNT=7499999;
56
57 led_run8 led_run8_test3(
58 .clk(clk),
59 .reset_n(reset_n),
60 .led(led[3])
61 );
62 defparam led_run8_test3.MCNT=9999999;
63 endmodule
64
65 //也可以使用下列方式例化
66 // led_run8
67 // #(
68 // .MCNT(2499999)
69 // )
70 上面和下面是等价的
71 // defparam led_run8_test0.MCNT=2499999;
72