题解 | #状态机与时钟分频#

https://www.nowcoder.com/practice/25d694a351b748d9808065beb6120025

`timescale 1ns/1ns

module huawei7(
    input wire clk  ,
    input wire rst  ,
    output reg clk_out
);

//*************code***********//
    reg [2:0]state;
    reg [2:0]nx_state;
    
    always @ (posedge clk or negedge rst) begin
        if (!rst)
            state<=0;
        else state<=nx_state;
    end
    
    always @ (*) begin
        case(state)
            0:nx_state<=1;
            1:nx_state<=2;
            2:nx_state<=3;
            3:nx_state<=4;
            4:nx_state<=1;
        endcase
    end
    
    always @ (*) begin 
        clk_out=state==1;
    end
    

//*************code***********//
endmodule
全部评论

相关推荐

06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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