未修改的///**************************************************************
**********************led_top.v***************
module led_top(input clk,
input rst_n,
output [7:0]led_h);
wire clk_led;
clk_design clk_design_inst(.clk(clk),
.rst_n(rst_n),
.clk_led(clk_led));
led led_inst(.clk_led(clk_led),
.clk(clk),
.rst_n(rst_n),
.led_h(led_h));
endmodule
*****************clk_design.v********************
module clk_design(input clk, //时钟的输入
input rst_n, // 复位
output clk_led); //led 的控制信号 .
reg[24:0] cnt;
parameter LED_CNT = 24_999_999;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
cnt <= 25'd0 ;
else if (cnt < LED_CNT )
cnt <= cnt + 1'b1 ;
else cnt <= 25'd0 ;
end
assign clk_led = (cnt == 25'd24_999_999)? 1'b1 : 1'b0;
endmodule
********************led.v**********
module led(input clk_led,
input rst_n,
input clk,
output reg[7:0] led_h);
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
led_h <= 8'd0;
else if (clk_led )
led_h <= led_h + 1'b1;
else
led_h <= led_h;
end
endmodule
******************************修改后***********
**********************led_top.v***************
module led_top(input clk,
input rst_n,
output [7:0]led_h);
wire clk_led;
clk_design clk_design_inst(.clk(clk),
.rst_n(rst_n),
.clk_led(clk_led));
led led_inst(.clk_led(clk_led),
// .clk(clk),
.rst_n(rst_n),
.led_h(led_h));
endmodule
*****************clk_design.v********************
module clk_design(input clk, //时钟的输入
input rst_n, // 复位
output clk_led); //led 的控制信号 .
reg[24:0] cnt;
parameter LED_CNT = 24_999_999;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
cnt <= 25'd0 ;
else if (cnt < LED_CNT )
cnt <= cnt + 1'b1 ;
else cnt <= 25'd0 ;
end
assign clk_led = (cnt == 25'd24_999_999)? 1'b1 : 1'b0;
endmodule
********************led.v**********
module led(input clk_led,
input rst_n,
// input clk,
output reg[7:0] led_h);
always@(posedge clk_led or negedge rst_n)
begin
if(!rst_n)
led_h <= 8'd0;
else if (clk_led )
led_h <= led_h + 1'b1;
else
led_h <= led_h;
end
endmodule
为啥修改后的那个.第一盏灯不亮.直接从第二盏开始计数.....还要..这个不用寄存器的初始状态...我用的是altera的EP3C5E144.