HDLBits_Lemmings4

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!

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值