27--状态机例程

//状态机设计的例子
module FSM(
input clk,
input clr,
input start,
input step2,
input step3,
output reg [2:0]out
);
reg [1:0]state,next_state;
parameter state0=2’b00,state1=2’b01,state2=2’b11,state3=2’b10;

always @(posedge clk or posedge clr)
begin
if(clr)state<=state0;
else state<=next_state;
end
always @(state or start or step2 or step3)
begin
case(state)
state0:begin
if(start)next_state<=state1;
else next_state<=state0;
end
state1:begin
next_state<=state2;
end
state2:begin
if(step2)next_state<=state3;
else next_state<=state0;
end
state3:begin
if(step3) next_state<=state0;
else next_state<=state3;
end
default:next_state<=state0;
endcase
end
always@(state)
begin
case(state)
state0:out=3’b001;
state1:out=3’b010;
state2:out=3’b100;
state3:out=3’b111;
default:out=3’b001;
endcase
end

endmodule

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值