HDLbits--Lemmings1

 根据题目描述:只要是碰到障碍物就会转向。

module top_module(
    input clk,
    input areset,    // Freshly brainwashed Lemmings walk left.
    input bump_left,
    input bump_right,
    output walk_left,
    output walk_right); //  

    // parameter LEFT=0, RIGHT=1, ...
    parameter l=0,r=1;
    reg state, next_state;

    always @(*) begin
        // State transition logic
        case(state)
            l:begin 
                if(!bump_left)
                next_state<=l;
                else
                    next_state<=r;
            end
            r:begin
                if(!bump_right)
                    next_state<=r;
                else
                    next_state<=l;
            end
        endcase
    end

    always @(posedge clk, posedge areset) begin
        // State flip-flops with asynchronous reset
        if(areset)
            state<=l;
        else
            state<=next_state;
    end

    // Output logic
    assign walk_left = (state == l);
    assign walk_right = (state == r);

endmodule

question  状态机组合逻辑一定要用case语句吗 ?

你可能感兴趣的:(fpga开发)