标签:ima out inf 报纸 mod sed strong tput lse
斜杠的左边是当前的输入,斜杠的右侧是输出信号。下图是网上找出的,有部分错误,在st1缺少状态。
代码:
module maib( input clk, input rst_n, input [2:0]din, //ABC [0]:1分钱 [1]:2分钱 [2]:5分钱 output reg [1:0]dout // [0]:输出报纸一份 [1]:找钱1分 ); parameter idle=7‘b000_0001; //空闲状态 parameter st1 =7‘b000_0010; //一共一分钱 parameter st2 =7‘b000_0100; //一共两分钱 parameter st3 =7‘b000_1000; //一共三分钱 parameter st4 =7‘b001_0000; //一共四分钱 parameter st5 =7‘b010_0000; //一共五分钱 parameter st6 =7‘b100_0000; // 六分钱了 reg [6:0]cur_state; //当前状态与下一状态 reg [6:0]nxt_state; //当前状态与下一状态 //在每个时钟的上升沿切换状态 always@(posedge clk or negedge rst_n) if(~rst_n) cur_state<=idle; else cur_state<=nxt_state; //切换到下一个应该到达的状态 //组合逻辑切换状态 always@(din) begin case(cur_state) idle: begin if(din==3‘b001) nxt_state<=st1; //有一分钱的状态 else if(din==3‘b010) nxt_state<=st2; //有两分钱的状态 else if(din==3‘b100) nxt_state<=st5; //有五分钱的状态 else nxt_state<=idle; end st1: //有一分钱了 begin if(din==3‘b001) nxt_state<=st2; //有两分钱的状态 else if(din==3‘b010) nxt_state<=st3; //有三分钱的状态 else if(din==3‘b000) nxt_state<=st1; //在有一分钱的状态保持 end st2: //有两分钱了 begin if(din==3‘b001) nxt_state<=st3; //有三分钱的状态 else if(din==3‘b010) nxt_state<=st4; //有四分钱的状态 else if(din==3‘b000) nxt_state<=st2; //在有两分钱的状态保持 end st3: //有三分钱了 begin if(din==3‘b001) nxt_state<=st4; //有四分钱的状态 else if(din==3‘b010) nxt_state<=st5; //有五分钱的状态 else if(din==3‘b000) nxt_state<=st3; //在有三分钱的状态保持 end st4: //有四分钱了 begin if(din==3‘b001) nxt_state<=st5; //有五分钱的状态 else if(din==3‘b010) nxt_state<=st6; //有六分钱的状态 else if(din==3‘b000) nxt_state<=st4; //在有两分钱的状态保持 end st5: begin nxt_state<=idle; end st6: begin nxt_state<=idle; end default:; endcase end always@(posedge clk ) if(nxt_state==st5) dout<=2‘b01; //不找钱 else if(nxt_state==st6) dout<=2‘b11; //找钱1分 endmodule
标签:ima out inf 报纸 mod sed strong tput lse
原文地址:https://www.cnblogs.com/luxinshuo/p/13552347.html