题解 | #输入序列连续的序列检测#

输入序列连续的序列检测

https://www.nowcoder.com/practice/d65c2204fae944d2a6d9a3b32aa37b39

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);
	parameter S0=0,S1=1,S2=2,S3=3,S4=4,S5=5,S6=6,S7=7,S8=8;
	reg [3:0] state,state_next;

always @(*) begin

case(state)
S0:begin if(a)  state_next=S0; else state_next=S1; end
S1:begin  if(a)  state_next=S2; else state_next=S1; end
S2:begin  if(a)  state_next=S3; else state_next=S1; end
S3:begin  if(a)  state_next=S4; else state_next=S1; end
S4:begin  if(a)  state_next=S0; else state_next=S5; end
S5:begin  if(a)  state_next=S0; else state_next=S6; end
S6:begin  if(a)  state_next=S0; else state_next=S7; end
S7:begin  if(a) state_next=S8; else  state_next=S1;end
S8:begin  if(a) state_next=S0; else  state_next=S1;end
default:begin if(a) state_next=S0; else  state_next=S1;end
endcase
end
  
  always @(posedge clk or negedge rst_n) begin
if(rst_n==0)
state<=S0;
else state<=state_next;
  end
   always @(posedge clk or negedge rst_n) begin
if(rst_n==0)
match<=0;
else match<=(state==S8)?1:0;
  end
endmodule

全部评论

相关推荐

05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 16:22
主包是26应届生,投大厂简历一直过不了初筛,想问问大家有必要花钱改简历吗
Java抽象带篮子:我之前专门发个帖子说不要付费改简历的,里面还详细写了简历怎么写,你可以去看看
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务