module flowled(
input sys_clk50,
input rst_n,
output reg[3:0] led
);
reg [23:0]cnt;
always @(posedge sys_clk50 or negedge rst_n)
begin
if(!rst_n)
cnt <=24'd0;
else
if(cnt<24'd10000000)
cnt <= cnt + 1'b1;
else
cnt <= 24'd0;
end
always @(posedge sys_clk50 or negedge rst_n)
begin
if(!rst_n)
led <=4'b0001;
else
if(cnt==24'd10000000)
led <= {led[2:0],led[3]}; //led右移一位 花括号移位寄存器
else
led <= led; //led状态不变
end
endmodule
/*拼接运算符 { } ;赋值 <=; 数据的高低位 [ ];
大括号内的东西表示把所列数据拼接成一串新的数据
如果 led[10:1]=2'b 000 000 000 1
运算led<={led[9:1],led[10]}
结果是将led右数第10位数,拼接在led右数第一位数到第九位数的右边
即新的led[10:1]=2'b 000 000 001 0
*/