题解 | 不重叠序列检测

不重叠序列检测

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
	);

reg [5:0] data_reg;
reg [2:0] cnt;

always@(posedge clk or negedge rst_n)
if(!rst_n)begin
	cnt <= 'd0;
end
else if(cnt == 3'd5)begin
	cnt <= 3'd0;
end
else begin
	cnt <= cnt + 1'b1;
end

always@(posedge clk or negedge rst_n)
if(!rst_n)begin
	data_reg <= 'b0;
end
else if(cnt <= 3'd5)begin
	data_reg <= {data,data_reg[5:1]};
end

always@(posedge clk or negedge rst_n)
if(!rst_n)begin
	match <= 1'b0;
	not_match <= 1'b0;
end
else if(cnt == 3'd5)begin
	if(data_reg == 6'b011100)begin
		match <= 1'b1;
		not_match <= 1'b0;
	end
	else begin
		match <= 1'b0;
		not_match <= 1'b1;
	end
end
else begin
		match <= 1'b0;
		not_match <= 1'b0;
end

endmodule

全部评论

相关推荐

03-03 23:42
复旦大学 Java
_无论云泥意贯一:把复旦大学放前面,山东大学放后面,并且在两个大学后面标注985(用一些显眼的颜色标注)
点赞 评论 收藏
分享
03-01 21:45
中北大学 golang
孤蓝长空:请你说一下为什么你用websocket而不是http,请你说一下什么是rpc,为什么用rpc,你的rpc的传输协议是JSON,xml还是什么 请你描述一下你的鉴权流程(完整的) 我问的是第二个项目,随便问的哈哈哈
开工第一帖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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