如下,是一部分三段式状态机的代码:
always@(posedge clk or negedge rst_n)
begin
if(!rst_n) cstate<=WR_S1;
else cstate<=nstate;
end
always@(cstate)
begin
case(cstate)
WR_S1: nstate=WR_S2;
WR_S2: nstate=WR_S3;
...
default:nstate=WR_S1
endcase
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n) cmd<=3'b111;
else begin
case(nstate)
WR_S1:cmd<=3'b101;
WR_S2:cmd<=3'b110;
...
default: ;
endcase
end
end
endmodule