FSM_Verilog实现Lemmming游戏

代码如下

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 ); 
	
	parameter left=0,right=1,left_ground=2,right_ground=3,left_dig=4,right_dig=5;
	reg [3:0]state,next_state;
	
always@(*)
	begin
		case(state)
			left:if(ground)
					if(dig)
						next_state<=left_dig;
					else
						next_state<=bump_left?right:left;
				else
				next_state<=left_ground;
				
			right:if(ground)
					if(dig)
						next_state<=right_dig;
					else
						next_state<=bump_right?left:right;
				else
					next_state<=right_ground;
				
			left_ground:if(ground)
							next_state<=left;
						else
							next_state<=left_ground;
							
			right_ground:if(ground)
							next_state<=right;
						else
							next_state<=right_ground;
							
			left_dig:if(ground)
						next_state<=left_dig;
					else
						next_state<=left_ground;
						
			right_dig:if(ground)
						next_state<=right_dig;
					else
						next_state<=right_ground;
		endcase
	end
	always@(posedge clk or posedge areset)
		if(areset)
			state<=left;
		else
			state<=next_state;

    assign walk_left = (state == left);
    assign walk_right = (state == right);
    assign aaah = ((state == left_ground) || (state == right_ground));
    assign digging = ((state == left_dig) || (state == right_dig));
endmodule

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值