zoukankan      html  css  js  c++  java
  • 流水灯实验

    开发板上有一排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
  • 相关阅读:
    spring boot + swagger2
    itext7 html转pdf实现
    shell脚本学习
    观察者模式
    sql mode 问题及解决 错误代码:1055 this is incompatible with sql_mode=only_full_group_by
    学生报数算法实现
    git reset 版本回退操作
    struts2方法无法映射问题:There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []
    Vue日历组件的功能
    vue-router 在新窗口打开页面的功能
  • 原文地址:https://www.cnblogs.com/fengyanlover/p/5021200.html
Copyright © 2011-2022 走看看