题解 | #根据状态转移写状态机-二段式#居然没人说好奇怪可恶啊 我看不懂。

根据状态转移写状态机-二段式

http://www.nowcoder.com/practice/5b2ff27610d04993ae92374d51bfc2e6

``` `timescale 1ns/1ns

module fsm2( input wire clk , input wire rst , input wire data , output reg flag );

//**code// /reg[2:0] s; always @(posedge clk or negedge rst )begin if (!rst)begin s<=0; flag<=0; end else begin if(data==1)begin if(s<=3)begin s<=s+1; flag<=0; end if(s==4)begin s<=1; flag<=1; end end else begin flag<=0; if(s==4)begin flag<=1; s<=0; end end end end/ parameter S0=0, S1=1, S2=2, S3=3, S4=4; reg [2:0] state, nstate; always@(data or rst or state) begin if(~rst) begin nstate <= S0; flag <= 0; end else case(state) S0: begin nstate <= data? S1: S0; flag <= 0; end S1: begin nstate <= data? S2: S1; flag <= 0; end S2: begin nstate <= data? S3: S2; flag <= 0; end S3: begin nstate <= data? S4: S3; flag <= 0; end S4: begin nstate <= data? S1: S0; flag <= 1; end default: begin nstate <= S0; flag <= 0; end endcase end
always@(posedge clk or negedge rst) begin if(~rst) state <= S0; else state <= nstate; end

//**code// endmodule

全部评论

相关推荐

10-07 20:48
门头沟学院 Java
不敢追175女神:可能是实习上着班想到后面还要回学校给导师做牛马,看着身边都是21-25的年纪,突然emo了了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务