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

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

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

`timescale 1ns/1ns

module seq_circuit(
   input                C   ,
   input                clk ,
   input                rst_n,
 
   output   wire        Y   
);
reg [1:0] q;
always@(posedge clk or negedge rst_n)begin
    if (~rst_n)begin
        q <= 2'b00;
    end
    else begin
        if (~C) begin
            case(q)
            2'b00:q <= 2'b00;
            2'b01:q <= 2'b11;
            2'b11:q <= 2'b11;
            2'b10:q <= 2'b00;
            endcase
        end
        else begin
            case(q)
            2'b00:q <= 2'b01;
            2'b01:q <= 2'b01;
            2'b11:q <= 2'b10;
            2'b10:q <= 2'b10;
            endcase
        end
    end
end
assign Y = ((q==2'b10)&(C==0))?0:(q[1]?1:0);
endmodule
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务