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

📄 dtmf.c

📁 一些基于TMS320 LF2407 DSP的实验程序
💻 C
字号:
/*******************************************************************/
#include "exp1_2407.h"
#include "math.h"
#define pi 3.1415927
#define Length 102
#define Len 8
/*******************************************************************/

  double x[Length],xc[Length],xr[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;
  unsigned int da_out;

void sys_ini()                  //系统初始化子程序
{
     asm(" setc INTM");         //禁止所有中断
     asm(" clrc SXM");          //抑制符号位扩展
     asm(" clrc OVM");          //累加器中结果正常溢出
     * WDCR=0x00E8;             //禁止看门狗
     WSGR=0x0649;               //io、ram、program都设为1等待读写
     * SCSR1=0x0021;            //CLKIN=7.3728M,CLKOUT=29.4912M,使能spi外围模块
     * MCRB=0xFE3F;             //使能spi引脚
     * IFR=0xFFFF;              //清所有中断标志位
}
   
void spi_ini()
{
     * SPICCR&=0x007F;          //复位spi 
     * SPICCR=0x004F;           //CLOCK POLARITY=1,16位数据格式
     * SPICTL=0x000E;           //禁止溢出中断,CLOCK PHASE=1,禁用spi中断,主模式,使能数据发送
     * SPISTS=0x0080;           //清除接收溢出中断标志
     * SPIBRR=0x0000;           //波特率为29.4912/4=7.3728M
     * SPICCR|=0x0080;          //启动spi工作
}

interrupt void nothing()        //哑中断子程序
{
     return;  
}

void delay()
{
     unsigned int k;
     for(k=0;k<50;k++);
}

int main(void)
{     
      int inkey,outkeyrow,outkeycol;
      char outkey; 
      int *out = (int*)0x2b00;
      int in[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
      int ks;
      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;     
      sys_ini();
 	  spi_ini();
 	  
  	  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;

        for (;;)
	{
	  for (ks=0; ks<16; ks++)  
	    {
	      inkey = in[ks];
	      if      (inkey==0)  {fr=fr3; fc=fc1;}
	      else if (inkey==1)  {fr=fr0; fc=fc0;}
	      else if (inkey==2)  {fr=fr0; fc=fc1;}
	      else if (inkey==3)  {fr=fr0; fc=fc2;}
	      else if (inkey==4)  {fr=fr1; fc=fc0;}
	      else if (inkey==5)  {fr=fr1; fc=fc1;}
	      else if (inkey==6)  {fr=fr1; fc=fc2;}
	      else if (inkey==7)  {fr=fr2; fc=fc0;}
	      else if (inkey==8)  {fr=fr2; fc=fc1;}
	      else if (inkey==9)  {fr=fr2; fc=fc2;}
	      else if (inkey==10) {fr=fr0; fc=fc3;}
	      else if (inkey==11) {fr=fr1; fc=fc3;}
	      else if (inkey==12) {fr=fr2; fc=fc3;}
	      else if (inkey==13) {fr=fr3; fc=fc3;}
	      else if (inkey==14) {fr=fr3; fc=fc0;}
	      else if (inkey==15) {fr=fr3; fc=fc2;}
	      for (i=0; i<Length; i++)
	      {
	      	xr[i] = sin(2*pi*fr*i/fs);
	  	xc[i] = sin(2*pi*fc*i/fs);
	  	x[i] = 1*(1.0*xc[i]+1.0*xr[i]);
	      }
          
              for (j=0; j<8; j++)
 	      {
	        for (i=0; i<Length; i++)
  	  	    {
	 	    da_out=(x[i]+1)*511.5;
	  	    * SPITXBUF=da_out<<2|0xC000;
	  	    delay();
	  	    }
	      }
		   
   	      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;
	    }
	  }
}

⌨️ 快捷键说明

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