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

📄 speaker.c.bak

📁 指示灯在定时器的定时中断中按照设计时间闪烁
💻 BAK
字号:


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

// Prototype statements for functions found within this file.
interrupt void cpu_timer0_isr(void);
void Delay(unsigned int nTime);

void delay_loop(void);
void Gpio_select(void);
void error(int);
void program_stop();
void Gpio_PortA(void);
void Gpio_PortB(void);
void Gpio_PortF(void);
void Gpio_PortDEG(void);

#define nMusicNumber 40
Uint16 var1 = 0;
Uint16 var2 = 0;
Uint16 var3 = 0;
Uint16 test_count = 0;
Uint16 Test_flag = 0;
Uint16 Test_var  = 0;
Uint16 Test_status[32];

Uint16 PASS_flag = 0;
unsigned int uWork;

int nAddStep,nStep,jishu=0;
unsigned int uWork,nCount;
unsigned int music[nMusicNumber][2]=
{
	{182,480},{151,480},{135,480},{121,480},{135,480},{151,480},{182,480},{0,480},
	{182,480},{151,480},{135,480},{121,480},{135,480},{151,480},{182,480},{0,480},
	{182,240},{151,240},{135,240},{121,240},{135,240},{151,240},{182,240},{0,240},
	{182,240},{151,240},{135,240},{121,240},{135,240},{151,240},{182,240},{0,240},
	{182,1920},{151,1920},{135,1920},{121,1920},{135,1920},{151,1920},{182,1920},{0,1920} 
};

void main(void)
{   
    unsigned int uWork1;
	int i,j,nCount=0;


// 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  


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

// Initialize the 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
   	CpuTimer0.RegsAddr = &CpuTimer0Regs;
	// Initialize timer period to maximum:	
	CpuTimer0Regs.PRD.all  = music[nCount][0];
	// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):	
	CpuTimer0Regs.TPR.all  = 0;
	CpuTimer0Regs.TIM.all  = 0;
	CpuTimer0Regs.TPRH.all = 0;
	// Make sure timer is stopped:
	CpuTimer0Regs.TCR.bit.TSS = 1;
	// Reload all counter register with period value:
	CpuTimer0Regs.TCR.bit.TRB = 1;
	// Reset interrupt counters:
	CpuTimer0.InterruptCount = 0;	         
// Configure CPU-Timer 0 to interrupt every second:
// 100MHz CPU Freq, 1 second Period (in uSeconds)
   ////i= music[nCount][0];
   ////ConfigCpuTimer(&CpuTimer0, 40, i*1000);
   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
   
   *(int *)0x108000=0;		// 初始化ICETEK-CTR
   *(int *)0x108000=0x80;
   *(int *)0x108000=0;
   *(int *)0x108007=0;			// 关闭东西方向的交通灯
   *(int *)0x108007=0x40;	// 关闭南北方向的交通灯
   *(int *)0x108000=0x8;
   *(int *)0x108000=0x8;
   Gpio_PortA();
   
   /*for(;;)
   {
    GpioDataRegs.GPADAT.bit.GPIOA1=1;
    Delay(100);
    GpioDataRegs.GPADAT.bit.GPIOA1=0;
    Delay(100);
    }*/
   
   
   while ( j<1 )
	{
		/*Delay(music[nCount][1]*12);	// 音长
		nCount++;
		if ( nCount>=nMusicNumber )
		{
			nCount=0; j++;
		}
		if ( music[nCount][0]==0 )
			StopCpuTimer0();		// 静音
		else
		{   
		    i= music[nCount][0];
			ConfigCpuTimer(&CpuTimer0, 100, i*1000); 	// 切换音符
			StartCpuTimer0();
		}*/
	}

} 


interrupt void cpu_timer0_isr(void)
{  
   CpuTimer0.InterruptCount++;

   // Acknowledge this interrupt to receive more interrupts from group 1
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
   GpioDataRegs.GPASET.bit.GPIOA1=1;
   /*if(jishu==0)
    { GpioDataRegs.GPASET.bit.GPIOA1=1;
      jishu=1;
     }
   else
    { GpioDataRegs.GPADAT.bit.GPIOA1=1; 
      jishu=0;
    }*/
    //StopCpuTimer0();
}

void Delay(unsigned int nDelay)
{
	int i,j,k=0;
	for ( i=0;i<nDelay;i++ )
		for ( j=0;j<64;j++ )
			k++;
}

void Gpio_PortA(void)
{    

// GPIO Test #2: 
// Configure Upper 8 bits of Port as inputs and lower 8 bits as outputs    
// Loop back bits [7:0] to bits [15:8]
// Don't set any input qualifier
 
    var1= 0x0000;       // sets GPIO Muxs as I/Os
    var2= 0x00FF;       // sets GPIO 15-8 DIR as inputs, 7-0 DIR as outputs
    var3= 0x0000;       // Don't set any input qualifier
    
    Gpio_select();    
    
    test_count = 0;
    Test_status[Test_var] = 0x0002;
    Test_var++;
    
    Test_status[Test_var] = 0xD0BE;      // Set the default value of status 
                                         // to "PASSED"
    GpioDataRegs.GPACLEAR.all = 0x00FF;  // Test Clear
    asm(" RPT #5 ||NOP");                             
    GpioDataRegs.GPASET.bit.GPIOA0=1;
 
}

void Gpio_select(void)
{
     EALLOW;
     
    GpioMuxRegs.GPAMUX.all=var1;   // Configure MUXs as digital I/Os or
    GpioMuxRegs.GPBMUX.all=var1;   // peripheral I/Os
    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 + -