设置好四个状态 画出状态图,就能了解case里的状态转换关系。
module top_module(
input clk,
input areset, // Freshly brainwashed Lemmings walk left.
input bump_left,
input bump_right,
input ground,
output walk_left,
output walk_right,
output aaah );
reg [1:0]state;
reg [1:0]next_state;
parameter L=0,R=1,LG=2,RG=3;//带G的意味ground==0
always@(*)begin
case(state)
L:next_state <= ground?(bump_left?R:L):LG ;
R:next_state <= ground?(bump_right?L:R):RG;
LG:next_state <= ground?L:LG;
RG:next_state <= ground?R:RG;
endcase
end
always@(posedge clk,posedge areset)begin
if(areset)
state<=L;
else state<=next_state;
end
assign aaah = (state == LG|state == RG);
assign walk_left = state ==L;
assign walk_right = state ==R;
endmodule