牛客进阶题目1:输入序列连续检测
检测01110001序列,满足序列则拉高match
可以用状态机和移位寄存器,懒得画状态转移图,直接用移位寄存器解
注意题中match在检测到序列后的下一周期拉高,所以需要延一拍
`timescale 1ns/1ns
module sequence_detect(
input clk,
input rst_n,
input a,
output reg match
);
reg[7:0] temp ;
always @(posedge clk or negedge rst_n) begin
if(!rst_n)
temp <= 'd0 ;
else
temp <= {temp[6:0],a};
end
always @(posedge clk or negedge rst_n) begin
if(!rst_n)
match <= 1'b0 ;
else if(temp==8'b01110001)
match <= 1'b1 ;
else
match <= 1'b0 ;
end
endmodule

浙公网安备 33010602011771号