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

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

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


`timescale 1ns/1ns

module seq_circuit(
      input                C   ,
      input                clk ,
      input                rst_n,
      output   wire        Y   
);
parameter 		ZERO  = 2'b00;
parameter 		ONE   = 2'b01;
parameter 		TWO   = 2'b10;
parameter 		THREE = 2'b11;
reg 	[1:0]	state;
always @(posedge clk or negedge rst_n) begin  
	if(~rst_n) begin
		state<= ZERO;
	end 
	else begin
		case (state)
		ZERO:begin
			if (C==1) begin
				state<=ONE;
			end
			else begin
				state<=ZERO;
			end
		end
		ONE:begin
			if (C==1) begin
				state<=ONE;
			end
			else begin
				state<=THREE;
			end
		end
		TWO:begin
			if (C==1) begin
				state<=TWO;
			end
			else begin
				state<=ZERO;
			end
		end
		THREE:begin
			if (C==1) begin
				state<=TWO;
			end
			else begin
				state<=THREE;
			end
		end
			default : state<=ZERO;
		endcase
	end
end
assign Y = (((state==TWO) & (C==1))|state==THREE)?1:0;
endmodule



#FPGA#
全部评论

相关推荐

自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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