功能:间隔时间为1s,4个led灯逐个点亮,循环往复
描述:定义一个1s计数器来控制灯的亮灭
时序图如下图所示:

代码:
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 ;
always@(posedge sclk or negedge rst_n)
if(!rst_n)
cnt <= 0 ;
else if(cnt==max)
cnt <= 0 ;
else
cnt <= cnt+1’b1 ;
always@(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 ;
always@(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

本文介绍了一个使用Verilog编写的FPGA流水灯控制器,设计中包含一个1秒计数器,使得4个LED灯以1秒间隔依次点亮,形成循环效果。代码中详细展示了如何利用时钟边沿触发器控制LED的状态切换。
最低0.47元/天 解锁文章
640

被折叠的 条评论
为什么被折叠?



