目录
控制模块
通过状态机完成相应功能
module TOP(clk,rst_n,en_n,led,a);
input clk;
input rst_n;
input en_n;
output [5:0] led;
output [4:0] a;
parameter s0 = 2'b00,
s1 = 2'b01,
s2 = 2'b10,
s3 = 2'b11;
reg [1:0] next_state;
reg [1:0] current_state;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
current_state <= s0;
else
current_state <= next_state;
end
reg [4:0] cnt;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
next_state <= s0;
cnt <= 5'd30;
end
else
case(current_state)
s0:
begin
if(en_n == 1'b1)
next_state <= s0;
else
begin
if(cnt == 4)
begin
next_state <= s1;
cnt <= 5'd3;
end
else
begin
cnt <= cnt - 1'b1;
end
end