📄 dtmf.c
字号:
extern void InitC5402(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],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;
/***********************************************************************
** Main Function Program
***********************************************************************/
void 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;
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;
/*input the key number from 0 to 15*/
InitC5402(); /* initialize C5402 DSP */
OpenMcBSP();
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++)
{
*out = (int)(x[i]*16300.0);
WRITEAD50(); /* Tone output*/
}
}
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 + -