verilog HDLBits刷题[Finite State Machines]“Lemmings3”---Lemmings3

发布时间:2026/9/20 17:13:49
verilog HDLBits刷题[Finite State Machines]“Lemmings3”---Lemmings3 1、题目See also: Lemmings1 and Lemmings2.In addition to walking and falling, Lemmings can sometimes be told to do useful things, like dig (it starts digging when dig1). A Lemming can dig if it is currently walking on ground (ground1 and not falling), and will continue digging until it reaches the other side (ground0). At that point, since there is no ground, it will fall (aaah!), then continue walking in its original direction once it hits ground again. As with falling, being bumped while digging has no effect, and being told to dig when falling or when there is no ground is ignored.(In other words, a walking Lemming can fall, dig, or switch directions. If more than one of these conditions are satisfied, fall has higher precedence than dig, which has higher precedence than switching directions.)Extend your finite state machine to model this behaviour.2、分析旅鼠3旅鼠可以左右前进碰到障碍物反向前进可以挖掘直到地面下降才前进按照之前的方向地面下降会发出“啊啊啊”的声音地面上升后又按照之前的方向前进。跌倒优先级高于挖掘而挖掘优先级高于切换方向3、代码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 left3b000,right3b001,dig_treasure_left3b010,dig_treasure_right3b011,fall_left3b100,fall_right3b101; reg [2:0]state,next_state; always(posedge clk,posedge areset)begin if(areset) stateleft; else statenext_state; end always(*)begin next_statestate; case(state) left:begin if(!ground) next_statefall_left; else if(dig) next_statedig_treasure_left; else if(bump_left) next_stateright; end right:begin if(!ground) next_statefall_right; else if(dig) next_statedig_treasure_right; else if(bump_right) next_stateleft; end dig_treasure_left:begin if(!ground) next_statefall_left; end dig_treasure_right:begin if(!ground) next_statefall_right; end fall_left:begin if(ground) next_stateleft; end fall_right:begin if(ground) next_stateright; end default:next_stateleft; endcase end always(*)begin case(state) left:{walk_left,walk_right,aaah,digging}4b1000; right:{walk_left,walk_right,aaah,digging}4b0100; dig_treasure_left:{walk_left,walk_right,aaah,digging}4b0001; dig_treasure_right:{walk_left,walk_right,aaah,digging}4b0001; fall_left:{walk_left,walk_right,aaah,digging}4b0010; fall_right:{walk_left,walk_right,aaah,digging}4b0010; default:{walk_left,walk_right,aaah,digging}4b0000; endcase end endmodule4、结果

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询