zoukankan      html  css  js  c++  java
  • 画出可以检测10010串的状态图

    状态转换图:

    module det(
    input clk,
    input rst_n,
    input d,  //数据输入
    output reg y   //检测结果输出
    );
    /*
     检测101101
    */
    //状态编码
    parameter idle=3'b000; //空闲状态
    parameter s1=3'b001;   //检测到1
    parameter s2=3'b010;   //检测到10
    parameter s3=3'b011;   //检测到101
    parameter s4=3'b100;   //检测到1011
    parameter s5=3'b101;   //检测到10110
    parameter s6=3'b110;   //检测到101101
    
    reg[2:0]cur_state,nxt_state;
    always@(posedge clk or negedge rst_n)
    if(!rst_n)
     cur_state<=idle;
    else 
     cur_state<=nxt_state; 
    
    always@(cur_state,d)
    begin
    case(cur_state)
    idle:
    begin
     if(d==1'b1)
      nxt_state<=s1;
     else 
      nxt_state<=idle;
    end 
    s1:
    begin
     if(d==1'b0)
      nxt_state<=s2;
     else 
      nxt_state<=idle;
    end 
    s2:
    begin
     if(d==1'b1)
      nxt_state<=s3;
     else 
      nxt_state<=idle;
    end 
    s3:
    begin
     if(d==1'b1)
      nxt_state<=s4;
     else 
      nxt_state<=idle;
    end 
    s4:
    begin
     if(d==1'b0)
      nxt_state<=s5;
     else 
      nxt_state<=idle;
    end 
    s5:
    begin
     if(d==1'b1)
      nxt_state<=s6;
     else 
      nxt_state<=idle;
    end 
    s6:
    begin
     if(d==1'b1)
      nxt_state<=s1;
     else 
      nxt_state<=idle;
    end 
    default:;
    endcase  
    end 
    
    always@(posedge clk or negedge rst_n)
    if(~rst_n)
     y<=1'b0;
    else if(nxt_state==s6)
     y<=1'b1;
    else 
     y<=1'b0;
    endmodule
  • 相关阅读:
    FastDFS 安装与使用
    leecode刷题(18)-- 报数
    时间戳转换日期格式
    嵌入式Linux的FTP服务端软件(stupid-ftpd)
    iMx280A测试声纹
    Linux 版本查询
    Linux下的目录结构
    uboot主Makefile分析
    uboot配置过程详解1
    路由器设置
  • 原文地址:https://www.cnblogs.com/luxinshuo/p/13552139.html
Copyright © 2011-2022 走看看