Lemmings4 HDLBits刷题
发布日期:2022-09-10 02:36:15 浏览次数:3 分类:技术文章

本文共 1404 字,大约阅读时间需要 4 分钟。

菜鸟第一次发文,模仿了dalao的状态图,然后自己画了一下,根据状态图将代码写出来。

计数超过20并且在地上时才能够飞溅。

 

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 );     reg [2:0] state,next;    reg [7:0] cnt;    parameter A=3'd0,B=3'd1,C=3'd2,D=3'd3,E=3'd4,F=3'd5,G=3'd6;     //A左,B左挖,C左掉,D右,E右挖,F右掉,G飞溅    always @(posedge clk or posedge areset)        begin            if(areset)                state <= A;            else                state <= next;        end    always @(*)        begin            case(state)                A:next = ground?(dig?B:(bump_left?D:A)):C;                B:next = ground?B:C;                C:next = cnt>=20?(ground?G:C):(ground?A:C);                D:next = ground?(dig?E:(bump_right?A:D)):F;                E:next = ground?E:F;                F:next = cnt>=20?(ground?G:F):(ground?D:F);                G:next = G;            endcase        end    always @(posedge clk)        begin            case(state)                C:cnt <= cnt + 1;                F:cnt <= cnt + 1;                default:cnt <= 0;            endcase        end    assign walk_left = (state == A);    assign walk_right = (state == D);    assign aaah = (state == C) | (state == F);    assign digging = (state == B) | (state == E);            endmodule

转载地址:https://blog.csdn.net/Great_Hercules/article/details/124987805 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LEMP构建高性能WEB服务器(CentOS+Nginx+PHP+MySQL)
下一篇:lement 下拉选择添加删除操作

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月22日 23时39分40秒