题解 | #不重叠序列检测#

不重叠序列检测

https://www.nowcoder.com/practice/9f91a38c74164f8dbdc5f953edcc49cc

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input data,
	output reg match,
	output reg not_match
	);
parameter s0=0,s1=1,s2=2,s3=3,s4=4,s5=5;
parameter sn0=6,sn1=7,sn2=8,sn3=9,sn4=10,sn5=11;
parameter idle=12;
reg [3:0]cs,ns;
always@(posedge clk or negedge rst_n)begin
	if(!rst_n)begin
		cs<=idle;
	end
	else begin
		cs<=ns;
	end
end
always@(*)begin
	if(!rst_n)begin
		ns=s5;
		match=0;
		not_match=0;
	end
	else begin
		case(cs)
		s0:begin
			ns=(data)?s1:sn1;
			match=0;
			not_match=0;
		end
		s1:begin
			ns=data?s2:sn2;
			match=0;
			not_match=0;
		end
		s2:begin
			ns=data?s3:sn3;
			match=0;
			not_match=0;
		end
		s3:begin
			ns=data?sn4:s4;
			match=0;
			not_match=0;
		end
		s4:begin
			ns=data?sn5:s5;
			match=0;
			not_match=0;
		end
		s5:begin
			ns=data?sn0:s0;
			match=1;
			not_match=0;
		end
		sn0:begin
			ns=sn1;
			match=0;
			not_match=0;
		end
		sn1:begin
			ns=sn2;
			match=0;
			not_match=0;
		end
		sn2:begin
			ns=sn3;
			match=0;
			not_match=0;
		end
		sn3:begin
			ns=sn4;
			match=0;
			not_match=0;
		end
		sn4:begin
			ns=sn5;
			match=0;
			not_match=0;
		end
		sn5:begin
			ns=data?sn0:s0;
			match=0;
			not_match=1;
		end
		idle:begin
			ns=data?sn0:s0;
			match=0;
			not_match=0;
		end
		default:begin
			ns=idle;
			match=0;
			not_match=0;			
		end
		endcase
	end
end
endmodule

全部评论

相关推荐

一表renzha:你点进去没打招呼他也会有提示的,之前我点进美的,还没打招呼,他马上给我发了不太合适哦
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
点赞 评论 收藏
分享
我面试,她问我有女朋友没
不太迷人的反派_:不过对象,还会结合你老家,意向城市等等,看你是否稳定。哥们,别多想
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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