⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 跑马灯.txt

📁 详细说明:这是一个TI DSP2812的GPIO的应用: 跑马灯程序,可以让8个Led灯,每隔一秒钟依序轮流闪烁,附录了完整的程序批注
💻 TXT
字号:
//###########################################################################
//
// file:  Example_281xGpio_Led.c  Edited by  Steven-Tsao  
//
// TITLE: DSP281x GPIO LED Test   
//
//
//        This program requires the DSP281x V1.00 header files.  
//        As supplied, this project is configured for "boot to H0" operation. 
//
//        To work properly this test requires hardware configuration described
//        below.
//
//###########################################################################

//###########################################################################

#include "DSP281x_Device.h"     // DSP281x Headerfile Include File
#include "DSP281x_Examples.h"   // DSP281x Examples Include File


// Prototype statements for functions found within this file.

Uint16 j=0x0001;
short i ;
 
void Gpio_select(void);
void delay_loop(Uint16 loop_time);

void main(void)
{

// Step 1. Initialize System Control registers, PLL, WatchDog, 
// peripheral Clocks to default state:
// This function is found in the DSP281x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initalize GPIO: 
// This example function is found in the DSP281x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();  // Skipped for this example  

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts 
   DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.  
// This function is found in the DSP281x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt 
// Service Routines (ISR).  
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
   InitPieVectTable();
   
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
// InitPeripherals(); // Not required for this example

// Step 5. User specific code 
 Gpio_select();
 
// *******************************************//
// ************    *************//

GpioDataRegs.GPACLEAR.all=0xFFFF; // All GpioAx to  OFF 
GpioDataRegs.GPADAT.all=j;    // First led light ON
delay_loop(1000);         // Delay 1[s]

while(1)             // 
{
 
 for(i=1;i<8;i++)        // The second led to eighth one lights by turns 
 { 
  j=0x0001<<(8*i);
  GpioDataRegs.GPADAT.all=j;
  delay_loop(1000);       // // Delay 1[s]
 }
 
 for(i=1;i<8;i++)
 { 
  j=0x1000>>(8*i);       // The seventh led to first one lights by turns
  GpioDataRegs.GPADAT.all=j;
  delay_loop(1000);       // Delay 1[s]
 }

}
  

}


void Gpio_select(void)
{
     EALLOW;
   
    GpioMuxRegs.GPAMUX.all = 0x0000;   // Configure MUXs as digital I/Os 
                                           
    GpioMuxRegs.GPADIR.all = 0xFFFF;   // GPIO PORTs  as output
  
    GpioMuxRegs.GPAQUAL.all = 0x0000;  // Set GPIO input qualifier values
  
    EDIS;     
}     

//  **********************************************  // 
// Delay time function : set i[ms] with delay time function
//  **********************************************  //

void delay_loop(Uint16 loop_time)
{
    short      i;
    
    for (i = 0; i < loop_time; i++) {asm(" RPT #100000 ||NOP ");}
}

 

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -