惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
博客园 - 【当耐特】
B
Blog
Stack Overflow Blog
Stack Overflow Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园 - 司徒正美
博客园 - 叶小钗
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - yf.x

超声波测距#倒车雷达#DE10-Lite 按键计数器#DE10-Lite 按键消抖#DE10-Lite 流水呼吸灯v2#DE10-Lite 流水呼吸灯-v1#DE10-Lite 呼吸灯-#DE10-Lite 流水灯#DE10-Lite#Verilog HDLBits_review 2015fsm 补码FSM-HDLbits 串行数据流输出其中的数据位-HDLbits 串行数据接收判断-HDLbits 输出PS2数据流-HDLbits PS2数据流检测状态机-HDLbits 独热码状态机-HDLbits 旅鼠4-HDLbits 旅鼠游戏3-HDLbits 旅鼠游戏2-HDLbits 水库水位控制问题-HDLbits 康威生命游戏-hdlbits
旅鼠游戏--HDLbits
yf.x · 2025-12-15 · via 博客园 - yf.x

游戏规则很简单,老鼠单向移动,撞墙就左右翻转。同时撞左右墙,就同时右左翻转。用状态机实现。

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;
reg state, next_state;

always @(*) begin
// State transition logic
case(state)
LEFT:if(bump_left)
next_state=RIGHT;
else if(!bump_left)
next_state=state;

RIGHT:if(bump_right)
next_state=LEFT;
else if(!bump_right)
next_state<=state;

endcase
end

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

// Output logic
assign walk_left = (state == LEFT);
assign walk_right = (state == RIGHT);

endmodule