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

📄 main_nonbios.c

📁 瑞泰实验箱例程-2812,
💻 C
字号:

#include "DSP281x_Device.h"				// Peripheral address definitions

#ifdef EXAMPLE_BIOS
    #include "example_BIOS.h"
#endif

#ifdef EXAMPLE_NONBIOS
    #include "example_nonBIOS.h"
#endif
#include "DSP281x_Device.h"     // DSP281x Headerfile Include File
#include "DSP281x_Examples.h"   // DSP281x Examples Include File
#include "aic23cfg.h"
#include "mcbspcfg.h"
#include "myapp.h"
#include "ctr.h"
#include "demo.h"
#include "filter.h"
#define SCANCODE_0 0x70
#define SCANCODE_1 0x69
#define SCANCODE_2 0x72
#define SCANCODE_3 0x7A
#define SCANCODE_4 0x6B
#define SCANCODE_5 0x73
#define SCANCODE_6 0x74
#define SCANCODE_7 0x6C
#define SCANCODE_8 0x75
#define SCANCODE_9 0x7D
#define SCANCODE_Del 0x49
#define SCANCODE_Enter 0x5A
#define SCANCODE_Plus 0x79
#define SCANCODE_Minus 0x7B
#define SCANCODE_Mult 0x7C
#define SCANCODE_Divid 0x4A
#define SCANCODE_Num 0x77
#define led *(int *)0xc0000
//#define LCDDELAY 1
Uint16 ConversionCount;
unsigned char cKey=0,cOldKey=0;
void Delay(unsigned int nTime);		// 延时子程序
/*fir参数*/
//#define PI 3.1415926
#define FIRNUMBER 64
//#define SIGNAL1F 1000
//#define SIGNAL2F 4500
/*低通滤波器系数,大约在2k以上的声音
被彻低率率调*/
long fHn[FIRNUMBER]={
     -22,
     -21,
     -21,
     -20,
     -19,
     -17,
     -13,
      -5,
       6,
      23,
      45,
      74,
     111,
     154,
     206,
     266,
     333,
     407,
     487,
     572,
     660,
     750,
     841,
     929,
    1014,
    1094,
    1166,
    1229,
    1282,
    1322,
    1350,
    1364,
    1364,
    1350,
    1322,
    1282,
    1229,
    1166,
    1094,
    1014,
     929,
     841,
     750,
     660,
     572,
     487,
     407,
     333,
     266,
     206,
     154,
     111,
      74,
      45,
      23,
       6,
      -5,
     -13,
     -17,
     -19,
     -20,
     -21,
     -21,
     -22
};
int fXn[FIRNUMBER]={ 0 };
int fInput,fOutput;
int fIn[256],fOut[256];
int bFir=0;
unsigned int uWork,bLCD,nScanCode,nMode,bShowAD;
unsigned int nSoundNumber,bPlayBack,bRecord,nCurrentSound,js,bls,bStop,bLongEnough,bFir1=0,bFir2=0,bFir1play=0;
#define SOUNDBUFFERLENGTH 0x0d000
unsigned int uSound[SOUNDBUFFERLENGTH];
int sound=0,sound1=0,soundfifo1=0,soundfifo2=0;

#define FIR_ORDER 50 /* Filter Order */
/* Create an Instance of FIRFILT_GEN module and place the object in "firfilt" section */
#pragma DATA_SECTION(fir, "firfilt");
FIR16 fir= FIR16_DEFAULTS;
/* Define the Delay buffer for the 50th order filterfilter and place it in "firldb" section */
#pragma DATA_SECTION(dbuffer,"firldb");
long dbuffer[(FIR_ORDER+2)/2];
/* Define Constant Co-efficient Array and place the .econst/.const section in
non-volatile memory */
const long coeff[(FIR_ORDER+2)/2]= FIR16_LPF50;
void init(FIR16_handle);
void calc(FIR16_handle);
FIR16 lpf, hpf;
FIR16 lpf = FIR16_DEFAULTS;
FIR16 hpf = FIR16_DEFAULTS;
main()
{   int i=0;
   /* 
       Step 1. Initialize System Control:
       PLL, WatchDog, enable Peripheral Clocks
       This example function is found in the scsl\scsl.src\DSP281x_SysCtrl.c file.
   */    
   InitSysCtrl();
   
   /* 
       Step 2. Initialize TLVAIC23
       Master ,44.1K Hz MICIN input  PHONE output,etc.
       This example function is found in the aic23cfg.c file.
   */    
   AIC23_cfg();
   
   /* 
       Step 3. Clear all interrupts and initialize PIE vector table:
       Disable CPU interrupts 
   */    
   DINT;
   
   /*   
       Step 4. 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 scsl\scsl.src\DSP281x_PieCtrl.c file.
   */   
   InitPieCtrl();
   
   /*

       Step 5. Disable CPU interrupts and clear all CPU interrupt flags:
   */    
   IER = 0x0000;
   IFR = 0x0000;
   
   /*
       Step 6. 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 bcsl\bcsl.src\DSP281x_PieVect.c.
   */
   InitPieVectTable();
   
   /*  
       Step 7. Step 2. Initialize McBSP
       Slave ,external clkxr fsxr ,etc.
       This example function is found in the mcbspcfg.c file.
   */
   McBSP_cfg();
   DINT;
   //bStop=1;js=nSoundNumber=bPlayBack=bRecord=nCurrentSound=bls=bStop=0;
   /*for ( i=FIRNUMBER-1;i>0;i-- )
		fXn[i]=0;*/
   bFir1=0;
   bFir=0;
   lpf.dbuffer_ptr=dbuffer;
   lpf.coeff_ptr=fHn;
   lpf.order=FIR_ORDER;
   lpf.init(&lpf);
   for(;;)
   { 
      while (McbspaRegs.SPCR2.bit.XRDY==0);	// 等待数据传输完成
       
       fInput=McbspaRegs.DRR1.all;
       fIn[i]=fInput;
       lpf.input=fInput;
       lpf.calc(&lpf);
       fOutput=lpf.output;   
       McbspaRegs.DXR2.all=fOutput;
       McbspaRegs.DXR1.all=fOutput;
       fOut[i]=fOutput;
       if(i>=256)  
       { 
         i=0;//设置软件断点
       }
       i++;
       
   }
   DINT;
}
interrupt void mcbspRxFifoIsr(void)
{
   if(bFir1)
   {     fInput=McbspaRegs.DRR1.all;
         lpf.input=fInput;
         lpf.calc(&lpf);
         fOutput=lpf.output;
         McbspaRegs.DXR2.all=fInput;
         McbspaRegs.DXR1.all=fOutput;
       
    } 
   McbspaRegs.MFFRX.bit.RXFFOVF_CLEAR=1;   // Clear Overflow flag
   McbspaRegs.MFFRX.bit.RXFFINT_CLEAR=1;   // Clear Interrupt flag
   PieCtrlRegs.PIEACK.all|=0x20;           // Issue PIE ack
}

void Delay(unsigned int nDelay)
{
	int ii,jj,kk=0;
	for ( ii=0;ii<nDelay;ii++ )
	{
		for ( jj=0;jj<512;jj++ )
		{
			//RefreshLEDArray();
			kk++;
		}
	}
}

char ConvertScanToChar(unsigned char cScanCode)
{
	char cReturn;
	
	cReturn=0;
	switch ( cScanCode )
	{
		case SCANCODE_0: cReturn='0'; break;
		case SCANCODE_1: cReturn='1'; break;
		case SCANCODE_2: cReturn='2'; break;
		case SCANCODE_3: cReturn='3'; break;
		case SCANCODE_4: cReturn='4'; break;
		case SCANCODE_5: cReturn='5'; break;
		case SCANCODE_6: cReturn='6'; break;
		case SCANCODE_7: cReturn='7'; break;
		case SCANCODE_8: cReturn='8'; break;
		case SCANCODE_9: cReturn='9'; break;
		case SCANCODE_Plus: cReturn='+'; break;
		case SCANCODE_Minus: cReturn='-'; break;
	}
	 
	return cReturn;
}


⌨️ 快捷键说明

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