• 流水灯实验


    开发板上有一排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
  • 相关阅读:
    BZOJ4401 块的计数
    poj2914 Minimum Cut 全局最小割模板题
    无向图求最小割集
    HDU3232 Crossing Rivers 数学期望问题
    poj1386 字符串类型的一笔画问题 欧拉回路
    HDU3018 几笔画(非1笔)
    欧拉路&&欧拉回路 概念及其练习
    欧拉回路基础 HDU1878 欧拉回路||并差集
    我的明天在何处
    哈夫曼树讲解
  • 原文地址:https://www.cnblogs.com/fengyanlover/p/5021200.html
Copyright © 2020-2023  润新知