Chinaunix首页 | 论坛 | 博客
  • 博客访问: 400608
  • 博文数量: 101
  • 博客积分: 2324
  • 博客等级: 大尉
  • 技术积分: 887
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-19 19:28
文章分类

全部博文(101)

文章存档

2012年(3)

2011年(60)

2010年(38)

分类: 嵌入式

2011-06-10 09:28:37

//状态机设计的例子

module FSM(clk,clr,out,start,step2,step3);
input clk,clr,start,step2,step3;
output[2:0] out;
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
 

阅读(4423) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~