module top_module(
input clk,
input areset, // Freshly brainwashed Lemmings walk left.
input bump_left,
input bump_right,
input ground,
input dig,
output walk_left,
output walk_right,
output aaah,
output digging );
reg [3:0] out_reg;
reg [4:0] count_fall = 5'b00000;
reg [2:0] state,next_state;
parameter[2:0] s0=3'b000,//left_ground_undig
s1=3'b001,//left_ground_dig
s2=3'b011,//left_unground_undig
s3=3'b111,//right_ground_undig
s4=3'b110,//right_ground_dig
s5=3'b100,//right_unground_undig
s6=3'b101;//die
always @(*) begin
case(state)
s0:begin
if(ground) begin
if(dig)
next_state = s1;
else if((!dig) & bump_left)
next_state = s3;
else
next_state = s0;
end
else
next_state = s2;
end
s1:begin
if(ground)
next_state = s1;
else
next_state = s2;
end
s2:begin
if(ground) begin
if(count_fall > 19)
next_state = s6;
else
next_state = s0;
end
else
next_state = s2;
end
s3:begin
if(ground) begin
if(dig)
next_state = s4;
else if((!dig) & bump_right)
next_state = s0;
else
next_state = s3;
end
else
next_state = s5;
end
s4:begin
if(ground)
next_state = s4;
else
next_state = s5;
end
s5:begin
if(ground) begin
if(count_fall > 19)
next_state = s6;
else
next_state = s3;
end
else
next_state = s5;
end
s6:begin
next_state = s6;
end
endcase
end
always @(posedge clk or posedge areset) begin
if(areset) begin
state <= s0;
end
else begin
case(state)
s2,s5: count_fall <= count_fall + 1'b1;
s0,s3:count_fall <= 5'b00000;
default:count_fall <= count_fall;
endcase
state <= next_state;
end
end
always @(*) begin
case(state)
s0:out_reg = 4'b1000;
s1:out_reg = 4'b0001;
s2:out_reg = 4'b0010;
s3:out_reg = 4'b0100;
s4:out_reg = 4'b0001;
s5:out_reg = 4'b0010;
s6:out_reg = 4'b0000;
endcase
end
assign {walk_left,walk_right,aaah,digging} = out_reg;
endmodule
显示在time=1910处报错,应该是无法跳转到死亡状态,迷惑。
//更新:
count_fall需要设置大一些,否则下落时间过长溢出。导致无法正常死亡。这里修改成[7:0] count_fall后,success!