zoukankan      html  css  js  c++  java
  • 黑金开发板状态机实现的可用按键控制的流水灯

    module state(CLOCK,RESET,LED,KEY_UP);
    input CLOCK,RESET,KEY_UP;
    output reg [3:0] LED;
    parameter s1=2'b00,s2=2'b01,s3=2'b10,s4=2'b11;
    reg [1:0] current_state,next_state;
    reg t;
    parameter T1s=23'd2_000_00000;
    reg [22:0] cnt;
    always @ (posedge CLOCK or negedge RESET)
    if(!RESET)
      begin
      cnt<=0;
      t<=0;
      end
        else if(cnt==T1s)
          begin
          cnt<=0;
          t<=~t;
          end
           else
            cnt<=cnt+1;
    //assign t=(cnt==T1s)? 1'b1:1'b0;

    always @ (posedge t or negedge RESET)
    if(!RESET)
     current_state<=s1;
      else
       current_state<=next_state;
       
    always @ (current_state)
    begin
     next_state=s1;
     case(current_state)
      s1: if(KEY_UP) next_state=s2;else next_state=s4;
      s2: if(KEY_UP) next_state=s3;else next_state=s1;
      s3: if(KEY_UP) next_state=s4;else next_state=s2;
      s4: if(KEY_UP) next_state=s1;else next_state=s3;
      default: next_state=s1;
      endcase
    end

    always @ (posedge t or negedge RESET)
    if(!RESET)
     LED<=4'b0000;
     else
     case(next_state)
      s1: LED<=4'b0001;
      s2: LED<=4'b0010;
      s3: LED<=4'b0100;
      s4: LED<=4'b1000;
      default: LED<=4'bzzzz;
     endcase
    endmodule

  • 相关阅读:
    快速掌握一个语言最常用的50%[转]
    技术路线的选择重要但不具有决定性 [转]
    图形、图像国外期刊 [转]
    SessionHelper.cs(20170223)
    PageHelper.cs(20170223)
    FileDown.cs(20170223)
    EncryptionHelper.cs(20170223)
    CookieHelper.cs(20170223)
    ConvertJson.cs(20170223)
    ConvertHex.cs(20170223)
  • 原文地址:https://www.cnblogs.com/luxiaolai/p/2585256.html
Copyright © 2011-2022 走看看