题解 | #序列发生器#

序列发生器

https://www.nowcoder.com/practice/1fe78a981bd640edb35b91d467341061

方法一:用计数器和Case语句实现
    reg [2:0] cnt;
    always@(posedge clk or negedge rst_n)begin
        if(!rst_n) cnt<=3'b0;
        else begin
            if(cnt==3'd5)
                cnt<=3'b0;
            else    cnt<=cnt+1'b1;
        end        
    end
    always@(posedge clk or negedge rst_n)begin
        if(!rst_n) data<=1'b0;
        else begin
            case(cnt)
                3'd0:data<=1'b0;
                3'd1:data<=1'b0;
                3'd2:data<=1'b1;
                3'd3:data<=1'b0;
                3'd4:data<=1'b1;
                3'd5:data<=1'b1;
            endcase
        end        
    end
方法二:循环移位实现(左移)

reg            [5:0]           data_reg;

 

always@(posedge clk or negedge rst_n)

    if(rst_n == 1'b0)

        data_reg <= 6'b001011;

    else if(data_reg == 6'b100000)

        data_reg <= 6'b001011;

    else

        data_reg <= (data_reg << 1);

 

always@(posedge clk or negedge rst_n)

    if(rst_n == 1'b0)

        data <= 1'b0;

    else

        data <= data_reg[5];

               

   

       


全部评论

相关推荐

11-03 15:31
门头沟学院 Java
斯卡蒂味的鱼汤:知道你不会来数马,就不捞你😂最近数马疯狂扩招,招聘要求挺低的,你能力肯定够,应该就是因为太强了,知道你不会来才不捞你
投递腾讯云智研发等公司10个岗位
点赞 评论 收藏
分享
评论
6
收藏
分享

创作者周榜

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