当前位置: 首页 > news >正文

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

1、题目

See also: Lemmings1.

In addition to walking left and right, Lemmings will fall (and presumably go "aaah!") if the ground disappears underneath them.

In addition to walking left and right and changing direction when bumped, when ground=0, the Lemming will fall and say "aaah!". When the ground reappears (ground=1), the Lemming will resume walking in the same direction as before the fall. Being bumped while falling does not affect the walking direction, and being bumped in the same cycle as ground disappears (but not yet falling), or when the ground reappears while still falling, also does not affect the walking direction.

Build a finite state machine that models this behaviour.

See also: Lemmings3 and Lemmings4.

2、分析

旅鼠游戏2:旅鼠可以左右行走,如果地面消失于脚下,它们会摔跤并发出“啊啊啊”的声音,;如果地面重新出现,它们就以之前的方向继续前进。注意掉落前的状态为左还是左,如此看来,可知有四种情况:向左,向右,掉落前向左,掉落前向右。

3、代码

module top_module( input clk, input areset, // Freshly brainwashed Lemmings walk left. input bump_left, input bump_right, input ground, output walk_left, output walk_right, output reg aaah ); parameter LEFT=2'b00,RIGHT=2'b01,fall_left=2'b10,fall_right=2'b11; reg [1:0]state,next_state; always@(*)begin next_state = state; case(state) LEFT:begin if(!ground) next_state=fall_left; else begin if(bump_left) next_state=RIGHT; else next_state=LEFT; end end RIGHT:begin if(!ground) next_state=fall_right; else begin if(bump_right) next_state=LEFT; else next_state=RIGHT; end end fall_left:begin if(ground) next_state=LEFT; else next_state=fall_left; end fall_right:begin if(ground) next_state=RIGHT; else next_state=fall_right; end default:next_state=LEFT; endcase end always@(posedge clk,posedge areset)begin if(areset) state<=LEFT; else state<=next_state; end always@(posedge clk,posedge areset)begin if(areset) aaah<=1'b0; else if(ground==1'b0) aaah<=1'b1; else aaah<=1'b0; end assign walk_left=(state==LEFT); assign walk_right=(state==RIGHT); endmodule

4、结果

http://www.jsqmd.com/news/1291378/

相关文章:

  • 2026年7月五指山优质的浴室柜定制厂家推荐,橱柜/铝合金/铝合金鞋柜/全铝/铝合金房间门,浴室柜定制厂家推荐 - 品牌推荐师
  • Sketch MeaXure:3分钟掌握设计标注自动化,效率提升300%
  • 掌握这 6 个 LangGraph 核心概念,真正理解 AI Agent 工作流
  • 上海GEO优化服务真的能提升网站流量吗?
  • SpringBoot同城二手交易配送系统架构设计与实践
  • C++与OpenCV环境配置及图像处理实战入门指南
  • 2026年7月广西省移动1000M融合宽带怎么选不踩坑_一篇说透 - 找卡家园
  • 3分钟快速上手:Yuedu书源配置终极指南,解锁海量免费小说阅读体验
  • AI Agent落地实战:从架构选型到成本优化的工程指南
  • Python数据分析实战:从数据清洗到可视化呈现的完整行业盈利分析流程
  • 4.1RAG知识库基础
  • 3步完成WSABuilds安装:在Windows 10/11上运行Android应用的最佳方案
  • 2026内江门窗投诉最少推荐榜:良率、安装、售后决定口碑 - 家居装修资讯
  • 工业自动化控制器选型指南:GSV与ACP系列对比
  • QT C++桌面应用开发实战:从登录界面到多窗口跳转的完整指南
  • STM32 ADC与DMA高效数据采集:原理、配置与实战避坑指南
  • STM32标准库工程模板搭建全解析:从零构建稳定可复用的开发环境
  • ppInk:Windows屏幕标注终极解决方案,让你的演示教学效率翻倍
  • LLM与传统检索融合:LIGHTRETRIEVER架构解析
  • FPGA中LFSR的Verilog实现:从原理到实战应用
  • 2026年7月广西省移动1000M融合宽带怎么选_新手避坑指南 - 找卡家园
  • Blender插件开发指南:从用户痛点到高效工作流优化
  • C++字符串拼接性能优化:从基础操作到高效Join实现
  • 2026内江门窗口碑稳定性推荐榜:25年老店与加盟品牌到底差在哪 - 家居装修资讯
  • 大模型智能体开发:核心架构与实战指南
  • 剪映自动化革命:Python脚本驱动的高效视频批量处理实战
  • 开源思源宋体:打破专业中文字体成本壁垒的技术解析
  • STM32 ADC与DMA高效数据采集:从原理到实战避坑指南
  • vibe coding:你正在从「写代码的人」变成「验收代码的人」-龍德明宇
  • SMUDebugTool:免费开源的AMD Ryzen处理器调试神器,轻松掌控硬件性能