下面代码是技术交流群里一位朋友的,经我稍改动了一下(//always@(posedge clk or negedge rst_n) always@(posedge clk ))
改动前:自动实现流水灯
改动后:按下rst复位后才能实现流水灯
猜想原因:程序刚开始执行时,即使没有按复位键,也会在刚上电时执行一次复位吗?不然led_r的初值是什么?
module johnson(clk,rst_n,led);
input clk,rst_n;
output [7:0] led;
reg[23:0] count;
//always@(posedge clk or negedge rst_n )
always@(posedge clk )
if(!rst_n)
count <= 24'b0;
else
count <= count+1'b1;
//--------------------------------
reg[7:0] led_r;
//always@(posedge clk or negedge rst_n)
always@(posedge clk )
if(!rst_n)
led_r <= 8'b00000001;
else
if(count == 24'hffffff)
led_r <= {led_r[6:0],led_r[7]};
assign led = led_r[7:0];
endmodule