• 三态状态机实现的流水灯


    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

  • 相关阅读:
    浅谈树状数组与线段树
    BZOJ1367:[Baltic2004]sequence
    浅谈左偏树
    BZOJ4003:[JLOI2015]城池攻占
    BZOJ2809:[APIO2012]dispatching
    BZOJ1455:罗马游戏
    模拟ssh远程执行命令
    基于TCP协议的socket套接字编程
    计算机网络基础知识
    元类( 控制对象产生和控制类产生)模板
  • 原文地址:https://www.cnblogs.com/luxiaolai/p/3424344.html
Copyright © 2020-2023  润新知