• 流水灯实验


    开发板上有一排LED灯,共26个,LEDR17-LEDR0-LEDG7-LEDG0;

    实现以1s间隔从左至右流,循环不断~

    完整代码如下(用的依旧是自动生成的模板):

    //=======================================================
    //  This code is generated by Terasic System Builder
    //=======================================================
    
    module LED_Test(
        //////////// CLOCK //////////
        CLOCK_50,
        RSTn,
        //////////// LED //////////
        LEDG,
        LEDR 
    );
    //=======================================================
    //  PORT declarations
    //=======================================================
    
    //////////// CLOCK //////////
    input                          CLOCK_50;
    input                            RSTn;
    //////////// LED //////////
    output             [8:0]        LEDG;
    output            [17:0]        LEDR;
    
    //=======================================================
    //  Structural coding
    //=======================================================

    //-----------------------定时器模板--------------------------
    //----1MS定时器
    parameter T1MS = 16'd49_999; reg [15:0] Count1; always@(posedge CLOCK_50 or negedge RSTn) if(!RSTn) Count1 <= 16'd0; else if(Count1 == T1MS) Count1 <= 16'd0; else Count1 <= Count1 + 1'b1; //----1S定时器 reg [9:0] Count_MS; always@(posedge CLOCK_50 or negedge RSTn) if(!RSTn) Count_MS <= 10'd0; else if(Count_MS == 16'd1000) Count_MS <= 10'd0; else if(Count1 == T1MS) Count_MS <= Count_MS + 1'b1;
    //----------------------------------------------------------
    //---------------------流水灯实现--------------------------- reg [26:0] rLED; always@(posedge CLOCK_50 or negedge RSTn) if(!RSTn) rLED <= 27'b1000_0000_0000_0000_0000_0000_00; else if(Count_MS == 16'd1000) begin if(rLED == 27'b0000_0000_0000_0000_0000_0000_001) //首尾交接处 rLED <= 27'b1000_0000_0000_0000_0000_0000_000; else if(rLED == 27'b0000_0000_0000_0000_0100_0000_000) //红绿LED交接处 rLED <= 27'b0000_0000_0000_0000_0001_0000_000; else rLED <= {1'b0,rLED[26:1]}; end
    //-----------------------------------------------------------------

    // 输出赋值 assign LEDR
    = rLED[26:9]; assign LEDG = {1'b0,rLED[7:0]}; //由于LEDG8跟它们一排LED不在同一排,所以就分出来置零好了 endmodule
  • 相关阅读:
    hdoj 4006 The kth great number【优先队列】
    hdoj 1509 Windows Message Queue【优先队列】
    nyoj 55 懒省事的小明【优先队列】
    hdoj 1896 Stones【优先队列】
    nyoj 757 期末考试【优先队列+贪心】
    hdoj 2147 kiki's game【博弈】
    hdoj 1873 看病要排队【优先队列】
    hdoj 1789 Doing Homework again
    nyoj 1036 非洲小孩【贪心区间选点】
    转:栈和队列小知识【STL用法】
  • 原文地址:https://www.cnblogs.com/fengyanlover/p/5021200.html
Copyright © 2020-2023  润新知