always @(posedge CLK_50M) //时钟上升沿、、、、。
begin
if(counter==24'h500000) //计数器
begin
clk_div<=~clk_div; //产生新的频率,分频器产生
counter<=24'h000000;
end
else
counter<=counter+1'b1;
end
always @(posedge clk_div or negedge RST_N)
begin
if(!RST_N)
begin
led<=8'hff;
led_state<=4'b0;
if(led_state > 4'b1000)
led_state <= 4'b0000;
end
else
begin
case (led_state) //状态机
4'b0000: led<=8'b1111_1111;
4'b0001: led<=8'b1111_1110;
4'b0010: led<=8'b1111_1101;
4'b0011: led<=8'b1111_1011;
4'b0100: led<=8'b1111_0111;
4'b0101: led<=8'b1110_1111;
4'b0110: led<=8'b1101_1111;
4'b0111: led<=8'b1011_1111;
4'b1000: led<=8'b0111_1111;
default:led<=8'b0000_0000;
endcase
led_state<=led_state+1'b1;
end
end