//*****************************************************
//** main code
//*****************************************************
//时钟50M,一个节拍就是 0.02us,先计数10000000*0.02us=0.2s
//计数器对系统时钟计数,计时0.2秒
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n)
counter <= 24'd0;
else if (counter < 24'd1000_0000)
counter <= counter + 1'b1;
else
counter <= 24'd0;
end
//通过移位寄存器控制IO口的高低电平,从而改变LED的显示状态
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n)
led <= 4'b0001;
else if(counter == 24'd1000_0000)
//这个移位语句当年困扰我好久
led[3:0] <= {led[2:0],led[3]};
else
led <= led;
end