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

📄 dtmf.c

📁 DSP5000实验箱上完整的实验程序,很有参考价值
💻 C
字号:
extern void InitC5410(void);
extern void OpenMcBSP(void);
extern void CloseMcBSP(void);
extern void WRITEAD50(void);

  #include "math.h"
  #include "stdio.h"
  #define pi 3.1415927
  #define Length 102
  #define Len 8
 
  double x[Length];
  double vk[Len][Length],vs1[Len],vs2[Len],v[3],s[Len],z[Len];
  double vkn[Len][Length];
  double fr0,fr1,fr2,fr3,fc0,fc1,fc2,fc3,fs,fr,fc;
  double m1,m0,max1,max2;
  int i,j;
  int *b = ( int *)0x1000;
/***********************************************************************
** Main Function Program
***********************************************************************/
void main(void)
{           
      int outkeyrow,outkeycol;
      char outkey;

	  InitC5410(); /* initialize C5402 DSP */
	  
	  fs = 8000;
  	  fr0 = 697.0;  fc0 = 1209.0;
  	  fr1 = 770.0;  fc1 = 1336.0;
  	  fr2 = 852.0;  fc2 = 1477.0;
  	  fr3 = 941.0;  fc3 = 1633.0;
  	  
  	  s[0] = fr0/fs;  s[4] = fc0/fs;
	  s[1] = fr1/fs;  s[5] = fc1/fs;
	  s[2] = fr2/fs;  s[6] = fc2/fs;
	  s[3] = fr3/fs;  s[7] = fc3/fs;
while(1)
     {	      
	  for(i=0;i<Length;i++)
	     {
  		   x[i]=(double)(*(b+i)/16300.0);
  		 }  
      for(i=0; i<Len; i++)
	  	 {
			v[2]=v[1]=v[0]=0;
			for (j=0; j<Length; j++)
			{
				v[2] = 2*(cos(2*pi*s[i]))*v[1]-v[0]+x[j];
				vk[i][j] = v[2];
				v[0] = v[1];
				v[1] = v[2];
			}	
	  	  }

	      for (i=0; i<Len; i++)
    	  {
			vs1[i] = vk[i][Length-1];
			vs2[i] = vk[i][Length-2];
	  	  }

		  for (i=0; i<Len; i++)
		  {
 	 		m1 = vk[i][Length-1] * vk[i][Length-1];
	  		m0 = vk[i][Length-2] * vk[i][Length-2];
	  		z[i] = m1+m0-2*cos(2*pi*s[i])*vk[i][Length-1]*vk[i][Length-2];
	  	  }
	  
	  	  max1=0.0;
	      
	  	  for (i=0; i<(Len/2); i++)
	  	  {
		  	if (z[i] >= max1) { max1 = z[i]; outkeyrow = i+1;}
	  	  }
	  
	  	  max2=0.0;
	      
		  for (i=4; i<Len; i++)
		  {
	  		if (z[i] >= max2) { max2 = z[i]; outkeycol = i-4+1;}
	  	  }
	  	  	 
/* Show the detceedt Key Number */ 
	  	  	 
	  	  if (outkeyrow==1)
	  	   	{
	  	   		if      (outkeycol==1) outkey = '1';
	  	   		else if (outkeycol==2) outkey = '2';
	  	   		else if (outkeycol==3) outkey = '3';
	  	   		else if (outkeycol==4) outkey = 'A';
	  	   	}
	  	  	 
	  	  else if (outkeyrow==2)
	  	   	{
	  	   		if      (outkeycol==1) outkey = '4';
	  	   		else if (outkeycol==2) outkey = '5';
	  	   		else if (outkeycol==3) outkey = '6';
	  	   		else if (outkeycol==4) outkey = 'B';
	  	   	}
	  	  	 
	  	  else if (outkeyrow==3)
	  	   	{
	  	   		if      (outkeycol==1) outkey = '7';
	  	   		else if (outkeycol==2) outkey = '8';
	  	   		else if (outkeycol==3) outkey = '9';
	  	   		else if (outkeycol==4) outkey = 'C';
	  	   	}
	  	  	 
	  	  else if (outkeyrow==4)
	  	   	{
	  	   		if      (outkeycol==1) outkey = '*';
	  	   		else if (outkeycol==2) outkey = '0';
	  	   		else if (outkeycol==3) outkey = '#';
	  	   		else if (outkeycol==4) outkey = 'D';
	  	   	}
	  	  	 
	  	  i=0;
	  	  i=0;
	    
	  }
}
/***********************************************************************
** End of File –– exp015.c
***********************************************************************/

⌨️ 快捷键说明

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