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

📄 example_dps2812m_dido.c

📁 TMS320F2812通用IO口驱动程序
💻 C
字号:
/* =================================================================================
File name:       	Example_DPS2812M_DA.C                    
                    
Originator:				SEED R&D Group
		
Description: 
                  DPS2812M Device Digital to Analog test program. 
=====================================================================================
 History:
-------------------------------------------------------------------------------------
 10-20-2005		Release	Rev 1.0         Jijunhui                                          
------------------------------------------------------------------------------*/

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

DIDO_DRV DIDO=DIDO_DRV_DEFAULTS;
const   long 	Tp = 7500;			//PeriodCounter=ControlPeriod*Freq(us*M);HISPCP  
const   long	CPUTime_T0 = 2500;       	   //CPU定时时间

// Prototype statements for functions found within this file.
void Gpio_select(void);
interrupt void cpu_timer0_isr(void);

void delay(void)
{
    int m,n;
    for (m=0;m<5000;m++) 
    {
      for (n=0;n<1000;n++)
      {
      }     
    }
}

void main(void)
{

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example 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
 
// For this example use the following configuration:
   Gpio_select();	  

// 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();

	
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.  
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.TINT0 = &cpu_timer0_isr;
   EDIS;    // This is needed to disable write to EALLOW protected registers

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   InitCpuTimers();   // For this example, only initialize the Cpu Timers

// Configure CPU-Timer 0 to interrupt every second:
// 100MHz CPU Freq, 1 second Period (in uSeconds)
   ConfigCpuTimer(&CpuTimer0, 150, CPUTime_T0);   
   StartCpuTimer0();

// Step 5. User specific code, enable interrupts:


// Enable CPU INT1 which is connected to CPU-Timer 0:
   IER |= M_INT1;

// Enable TINT0 in the PIE: Group 1 interrupt 7
   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

// Enable global Interrupts and higher priority real-time debug events:
   EINT;   // Enable Global interrupt INTM
   ERTM;   // Enable Global realtime interrupt DBGM

   while(1) {};
} 	

interrupt void cpu_timer0_isr(void)
{
   DIDO.DIDOPro(&DIDO); 
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;	

}

void DIDOPro(DIDO_DRV *v)
{ 
    if(v->TestSel ==1)
    {

   		GpioDataRegs.GPASET.all    =0xAAAA;
   		GpioDataRegs.GPACLEAR.all  =0x5555;     			   
       
  		GpioDataRegs.GPBSET.all    =0xAAAA;
  		GpioDataRegs.GPBCLEAR.all  =0x5555;     
   
   		GpioDataRegs.GPDSET.all    =0x0022;
   		GpioDataRegs.GPDCLEAR.all  =0x0041;    // Four I/Os only

   		GpioDataRegs.GPESET.all    =0x0002;
   		GpioDataRegs.GPECLEAR.all  =0x0005;    // ThreeI/Os only
               
   		GpioDataRegs.GPFSET.all    =0xAAAA;
   		GpioDataRegs.GPFCLEAR.all  =0x5555;    
                  
  		GpioDataRegs.GPGSET.all    =0x0020;
        GpioDataRegs.GPGCLEAR.all  =0x0010;    // Two  I/Os only
       	v->TestSel =0;
    }
    else 
    {
        GpioDataRegs.GPACLEAR.all  =0xAAAA;
        GpioDataRegs.GPASET.all    =0x5555;     			   
       
        GpioDataRegs.GPBCLEAR.all  =0xAAAA;
        GpioDataRegs.GPBSET.all    =0x5555;     
                   
        GpioDataRegs.GPDCLEAR.all  =0x0022;
        GpioDataRegs.GPDSET.all    =0x0041;    // Four I/Os only

        GpioDataRegs.GPECLEAR.all  =0x0002;
        GpioDataRegs.GPESET.all    =0x0005;    // ThreeI/Os only
               
        GpioDataRegs.GPFCLEAR.all  =0xAAAA;
        GpioDataRegs.GPFSET.all    =0x5555;    
                  
        GpioDataRegs.GPGCLEAR.all  =0x0020;
        GpioDataRegs.GPGSET.all    =0x0010; 
       	v->TestSel =1;
    }

}

void Gpio_select(void)
{

    Uint16 var1;
    Uint16 var2;
    Uint16 var3;

    var1= 0x0000;		// sets GPIO Muxs as I/Os
    var2= 0xffff;		// sets GPIO DIR as outputs
    var3= 0x0000;		// sets the Input qualifier values
   
    EALLOW;
	 
	GpioMuxRegs.GPAMUX.all=var1;
    GpioMuxRegs.GPBMUX.all=var1;   
    GpioMuxRegs.GPDMUX.all=var1;
    GpioMuxRegs.GPFMUX.all=var1;		 
    GpioMuxRegs.GPEMUX.all=var1; 
    GpioMuxRegs.GPGMUX.all=var1;
										
    GpioMuxRegs.GPADIR.all=var2;		// GPIO PORTs  as output
    GpioMuxRegs.GPBDIR.all=var2;   		// GPIO DIR select GPIOs as output 
    GpioMuxRegs.GPDDIR.all=var2;
    GpioMuxRegs.GPEDIR.all=var2;		
    GpioMuxRegs.GPFDIR.all=var2; 
    GpioMuxRegs.GPGDIR.all=var2;

    GpioMuxRegs.GPAQUAL.all=var3;  		// Set GPIO input qualifier values
    GpioMuxRegs.GPBQUAL.all=var3;   
    GpioMuxRegs.GPDQUAL.all=var3;
    GpioMuxRegs.GPEQUAL.all=var3;
    
       
 
    EDIS;
     
}     
//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

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