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

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

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] cur_state;
reg [1:0] nex_state;

always@(posedge clk or negedge rst_n)begin
    if(!rst_n)
        cur_state <= 2'b00;
    else
        cur_state <= nex_state;
end

always@(*)begin
    case(cur_state)
        2'b00:   nex_state = (C == 1)? 2'b01 : 2'b00;
        2'b01:   nex_state = (C == 1)? 2'b01 : 2'b11;
        2'b10:   nex_state = (C == 1)? 2'b10 : 2'b00;
        2'b11:   nex_state = (C == 1)? 2'b10 : 2'b11;
        default: nex_state = 2'b00;
    endcase
end

assign  Y =  ((cur_state == 2'b11) | (cur_state == 2'b10 & C == 1)) ? 1'b1 : 1'b0;

endmodule

全部评论

相关推荐

点赞 评论 收藏
分享
想按时下班的大菠萝在...:隔壁学校的,加油多投, 实在不好找可以下个学期开学找,把算法八股准备好,项目有空再换换
投了多少份简历才上岸
点赞 评论 收藏
分享
07-21 12:41
已编辑
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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