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

输入序列连续的序列检测

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

`timescale 1ns/1ns
module sequence_detect(
    input clk,
    input rst_n,
    input a,
    output reg match
    );
reg    [2:0]    state;
reg            match_flag;
always@(posedge clk or negedge rst_n)
    if(!rst_n)
        state <= 3'd0;
    else    begin
        case(state)  
            3'd0:    begin
                    if(a==1'b0)
                        state <= 3'd1;
                    else
                        state <= 3'd0;
                    end
            3'd1:    begin
                    if(a==1'b1)
                        state <= 3'd2;
                    else
                        state <= 3'd0;
                    end
            3'd2:    begin
                    if(a==1'b1)
                        state <= 3'd3;
                    else
                        state <= 3'd0;
                    end
            3'd3:    begin
                    if(a==1'b1)
                        state <= 3'd4;
                    else
                        state <= 3'd0;
                    end
            3'd4:    begin
                    if(a==1'b0)
                        state <= 3'd5;
                    else
                        state <= 3'd0;
                    end
            3'd5:    begin
                    if(a==1'b0)
                        state <= 3'd6;
                    else
                        state <= 3'd0;
                    end
            3'd6:    begin
                    if(a==1'b0)
                        state <= 3'd7;
                    else    
                        state <= 3'd0;
                    end
            3'd7:    begin
                    if(a==1'b1)    
                        state <= 3'd0;
                    else
                        state <= 3'd0;
                    end
            default:    ;
        endcase
end

always@(posedge clk&nbs***egedge rst_n)
    if(!rst_n)    
        match_flag <= 1'b0;
    else    if(state == 3'd7&&a==1'b1)
        match_flag <= 1'b1;
    else
        match_flag <= 1'b0;

always@(posedge clk&nbs***egedge rst_n)
    if(!rst_n)    
        match <= 1'b0;
    else
        match <= match_flag;

endmodule
全部评论

相关推荐

01-19 12:48
门头沟学院 C++
只想搞钱的鸽子很喜欢...:混账是很多的,还有那些在自己风华正茂的年纪说风凉话讥讽那些下岗前员工的。这些人都是现在职场环境这么烂的帮凶
点赞 评论 收藏
分享
程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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