zoukankan      html  css  js  c++  java
  • 三态状态机实现的流水灯

    module led(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;
    parameter T1s=31'd2_000_0000;
    reg [31:0] cnt;
    reg t;
    always @(posedge CLOCK or  negedge RESET)
    if(!RESET)
     begin
      t<=0;
      cnt<=0;
     end
        else if(cnt==T1s)
         begin
          cnt<=0;
          t<=~t;
         end
            else
             cnt<=cnt+1;
    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:begin if(KEY_UP) next_state<=s2;else next_state<=s4;end
         s2:begin if(KEY_UP) next_state<=s3;else next_state<=s1;end
         s3:begin if(KEY_UP) next_state<=s4;else next_state<=s2;end
         s4:begin if(KEY_UP) next_state<=s1;else next_state<=s3;end
         default: next_state<=2'bzz;
         endcase
    end
    always @(current_state)
    begin
     LED<=4'b0000;
          case(current_state)
         s1:LED<=4'b0001;
         s2:LED<=4'b0010;
         s3:LED<=4'b0100;
         s4:LED<=4'b1000;
         default:LED<=4'bzzzz;
          endcase
    end
     
    endmodule

  • 相关阅读:
    spring + junit 测试
    备份mysql数据库
    JAVA访问Zabbix API
    pro git 读书笔记 3 Git 分支
    pro git 读书笔记 1
    pro git 读书笔记 2
    溢出和剪裁,可见性
    html 与 jsp 文件格式区别
    Eclipse 的 CheckStyle 插件
    【转】单元测试覆盖率
  • 原文地址:https://www.cnblogs.com/luxiaolai/p/3424344.html
Copyright © 2011-2022 走看看