我爱嵌入式系统

当前位置:首页 > 软件天地 > 业内资讯 > 详细内容
TI DSP2812的GPIO的应用: 跑马灯程序
发布时间:2009/11/15  阅读次数:2466  字体大小: 【】 【】【

详细说明:这是一个TI DSP2812的GPIO的应用: 跑马灯程序,可以让8个Led灯,每隔一秒钟依序轮流闪烁,附录了完整的程序批注

//###########################################################################
//
// 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.
//===========================================================================

我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[1]
  • 评论人:[匿名] 时间: [2011/1/7 23:58:46] IP:[119.145.72.18*]
  • 为什么循环体内j和i每次都要左移或右移8位

51RTOS.com 版权所有  

Copyright 20006-2009 我爱嵌入式 ( 51RTOS.com ) All rights reserved 沪ICP备09080633号