集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1907|回复: 1

状态机举例-Verilog HDL 代码

[复制链接]
老怪甲 该用户已被删除
老怪甲 发表于 2010-5-28 10:48:18 | 显示全部楼层 |阅读模式
本帖最后由 fpgaw 于 2010-11-18 16:00 编辑

状态机举例-Verilog HDL 程序举例

一个同步状态机

Verilog HDL: Synchronous State Machine

This is a Verilog example that shows the implementation of a state machine.
The first CASE statement defines the outputs that are dependent on the value of the state machine variable state.
The second CASE statement defines the transitions of state machine and the conditions that control them.



statem.v

module statem(clk, in, reset, out);

input clk, in, reset;
output [3:0] out;

reg [3:0] out;
reg [1:0] state;

parameter zero=0, one=1, two=2, three=3;

always @(state)
   begin
     case (state)
        zero:
          out = 4'b0000;
        one:
          out = 4'b0001;
        two:
          out = 4'b0010;
        three:
          out = 4'b0100;
        default:
          out = 4'b0000;
     endcase
   end

always @(posedge clk or posedge reset)
   begin
     if (reset)
        state = zero;
     else
        case (state)
          zero:
             state = one;
          one:
             if (in)
               state = zero;
             else
               state = two;
          two:
             state = three;
          three:
             state = zero;
        endcase
   end

endmodule
weibode01 发表于 2010-11-9 11:14:59 | 显示全部楼层
状态机是很有用的一个东西
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-5-4 20:27 , Processed in 0.072697 second(s), 24 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表