题解 | #根据状态转移图实现时序电路#

根据状态转移图实现时序电路

https://www.nowcoder.com/practice/e405fe8975e844c3ab843d72f168f9f4

`timescale 1ns/1ns

module seq_circuit(
   input                C   ,
   input                clk ,
   input                rst_n,
 
   output   wire        Y   
);

    parameter st_00 = 2'b00;
    parameter st_01 = 2'b01;
    parameter st_10 = 2'b10;
    parameter st_11 = 2'b11;

    reg [1:0] st_cur;
    reg [1:0] st_next;

    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            st_cur <= 2'b00;
            st_next <= 2'b00;
        end
        else begin
            st_cur <= st_next;
        end
    end
    reg Y0;
    always @(*) begin
        case(C)
            0:
                case(st_cur)
                    2'b00: begin st_next <= st_00; Y0 <= 0; end
                    2'b01: begin st_next <= st_11; Y0 <= 0; end
                    2'b10: begin st_next <= st_00; Y0 <= 0; end
                    2'b11: begin st_next <= st_11; Y0 <= 1; end
                endcase
            1:
                case(st_cur)
                    2'b00: begin st_next <= st_01; Y0 <= 0; end
                    2'b01: begin st_next <= st_01; Y0 <= 0; end
                    2'b10: begin st_next <= st_10; Y0 <= 1; end
                    2'b11: begin st_next <= st_10; Y0 <= 1; end
                endcase
        endcase
    end

    assign Y = Y0;

                    
endmodule

全部评论

相关推荐

头像
10-27 15:50
门头沟学院 Java
想进开水团喝开水:有一种店 只能外卖 不能堂食 你猜为什么
点赞 评论 收藏
分享
12-08 15:35
浙江大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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