题解 | #根据状态转移图实现时序电路#
根据状态转移图实现时序电路
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]state,state_next; reg Y_r; assign Y = Y_r; always@(posedge clk or negedge rst_n) begin if(~rst_n) state <= 2'h0; else state <= state_next; end always @(*) begin case(state) 2'b00: state_next = C?2'b01:2'b00; 2'b01: state_next = C?2'b01:2'b11; 2'b10: state_next = C?2'b10:2'b00; 2'b11: state_next = C?2'b10:2'b11; endcase end always@(*) begin case(state) 2'b00: Y_r=1'b0; 2'b01: Y_r=1'b0; 2'b10: Y_r=C?1'b1:1'b0; 2'b11: Y_r=1'b1; endcase end endmodule