功能:间隔时间为1s,4个led灯逐个点亮,循环往复

描述:定义一个1s计数器来控制灯的亮灭

时序图如下图所示:

6.FPGA_Verilog流水线流水灯

代码:

module run_led(

input wire sclk ,
input wire rst_n ,

output reg led0 ,
output reg led1 ,
output reg led2 ,
output reg led3

);

parameter max = 49_999_999 ;

reg [25:0] cnt ;
[email protected](posedge sclk or negedge rst_n)
if(!rst_n)
cnt <= 0 ;
else if(cnt==max)
cnt <= 0 ;
else
cnt <= cnt+1’b1 ;

[email protected](posedge sclk or negedge rst_n)
if(!rst_n)
led0 <= 1 ;
else if(cnt==max&&led0==1)
led0 <= 0 ;
else if(cnt==max&&led3==1)
led0 <= 1 ;

[email protected](posedge sclk or negedge rst_n)
if(!rst_n)
led1 <= 0 ;
else if(cnt==max&&led0==1)
led1 <= 1 ;
else if(cnt==max&&led0==0)
led1 <= 0 ;

[email protected](posedge sclk or negedge rst_n)
if(!rst_n)
led2 <= 0 ;
else if(cnt==max&&led1==1)
led2 <= 1 ;
else if(cnt==max&&led1==0)
led2 <= 0 ;

[email protected](posedge sclk or negedge rst_n)
if(!rst_n)
led3 <= 0 ;
else if(cnt==max&&led2==1)
led3 <= 1 ;
else if(cnt==max&&led2==0)
led3 <= 0 ;

endmodule

相关文章: