我用的是并口通讯测试语音模块的ASR 但是一直不对 80C

#include"reg511.h"
#include "intrins.h"

#define uint8 unsigned char
#define uint16 unsigned int
#define uint32 unsigned long
sbit LD_WR = P3^6;
sbit LD_RD = P3^7;
sbit LD_A0 = P1^1;
sbit RSTB=P1^2;
sbit CSB=P1^0;
sbit out_1=P2^0;
sbit out_2=P2^1;
sbit out_3=P2^2;
sbit out_4=P2^3;
sbit out_5=P2^4;
sbit out_6=P2^5;
sbit out_7=P2^6;
sbit out_8=P2^7;
#define chu_yu 1
#define ke_shou 2
#define you_du 3
#define qi_ta 4
#define guan 0
#define MIC_VOL 0x43
#define CLK_IN 33.1776 /* user need modify this value according to clock in */
#define LD_PLL_11 (uint8)((CLK_IN/2.0)-1)
#define LD_PLL_ASR_19 (uint8)(CLK_IN*32.0/(LD_PLL_11+1) - 0.51)
#define LD_PLL_ASR_1B 0x48
#define LD_PLL_ASR_1D 0x1f
#define LD_ASR_NONE 14
#define LD_ASR_RUNING 15
#define LD_ASR_FOUNDOK 17

#define LD_ASR_FOUNDZERO 12

#define LD_ASR_ERROR 11
#define LD_MODE_ASR_RUN 0x08
#define LD_MODE_IDLE 0x00
uint8 idata nLD_Mode = LD_MODE_IDLE; // 用来记录当前是在进行ASR识别还是在播放MP3
uint8 idata nAsrStatus=0;
uint8 gu=0;
void delay(unsigned long uldata)
{
unsigned int j = 0;
unsigned int g = 0;
for (j=0;j<5;j++)
{
for (g=0;g<uldata;g++)
{
nop();
nop();
nop();
}
}
}

void LD_WriteReg( unsigned char address, unsigned char dataout )
{
P0 = address;
LD_A0 = 1;
CSB = 0;
LD_WR = 0;
nop();_nop_();_nop_();

LD_WR = 1;
CSB = 1;

nop();_nop_();_nop_();

P0 = dataout;
LD_A0 = 0;
CSB = 0;
LD_WR = 0;

nop();_nop_();_nop_();

LD_WR = 1;
CSB = 1;

nop();_nop_();_nop_();
}

unsigned char LD_ReadReg( unsigned char address )
{
unsigned char datain;

P0 = address;
LD_A0 = 1;
CSB = 0;
LD_WR = 0;

nop();_nop_();_nop_();

LD_WR = 1;
CSB = 1;

nop();_nop_();_nop_();

LD_A0 = 0;
CSB = 0;
LD_RD = 0;

nop();_nop_();_nop_();

datain = P0;
LD_RD = 1;
CSB = 1;

nop();_nop_();_nop_();

return datain;

}

void LD_reset()
{
RSTB=1;
delay(1);
RSTB=0;
delay(1);
RSTB=1;

delay(1);
CSB=0;
delay(1);
CSB=1;
delay(1);

}
void LD_Init_Common(void)
{

LD_ReadReg(0x06);
LD_WriteReg(0x17, 0x35);  
 delay(10);  
LD_ReadReg(0x06);  
LD_WriteReg(0x89, 0x03);   
delay(5); 
LD_WriteReg(0xCF, 0x43);    
delay(5);
LD_WriteReg(0xCB, 0x02);
/*PLL setting*/  
LD_WriteReg(0x11, LD_PLL_11);
LD_WriteReg(0x1E,0x00); 

//!!注意,下面三个寄存器,会随晶振频率变化而设置不同
//!!注意,请根据使用的晶振频率修改参考程序中的

LD_WriteReg(0x19, LD_PLL_ASR_19);

LD_WriteReg(0x1B, LD_PLL_ASR_1B);

LD_WriteReg(0x1D, LD_PLL_ASR_1D);
delay(10);
LD_WriteReg(0xCD, 0x04);
LD_WriteReg(0x17, 0x4c);
delay(5);
LD_WriteReg(0xB9, 0x00);
LD_WriteReg(0xCF, 0x4F);
LD_WriteReg(0x6F, 0xFF);
}
void LD_Init_ASR(void)
{
nLD_Mode=LD_MODE_ASR_RUN;
LD_Init_Common();
LD_WriteReg(0xBD,0x00);
LD_WriteReg(0x17,0x48);
delay( 10 );
LD_WriteReg(0x3C,0x80);
LD_WriteReg(0x3E,0x07);
LD_WriteReg(0x38,0xff);
LD_WriteReg(0x3A,0x07);
LD_WriteReg(0x40,0x00);
LD_WriteReg(0x42,0x08);
LD_WriteReg(0x44,0x00);
LD_WriteReg(0x46,0x08);
delay( 1 );
}
uint8 LD_Check_ASRBusyFlag_b2(void)
{
uint8 j;
uint8 flag = 0;
for (j=0; j<10; j++)
{
if (LD_ReadReg(0xb2) == 0x21)
{
flag = 1;
break;
}
delay(10);
}
return flag;
}
uint8 LD_AsrAddFixed(void)
{
uint8 k, flag;
uint8 nAsrAddLength;
const char sRecog[5][13] = {"chu yu", "ke shou",
"you du", "qi ta", "guan"};
const uint8 pCode[5] = {chu_yu, ke_shou, you_du, guan};
flag = 1;
for (k=0; k<5; k++)
{
if(LD_Check_ASRBusyFlag_b2() == 0)
{
flag = 0;
break;
}
LD_WriteReg(0xc1, pCode[k] );
LD_WriteReg(0xc3, 0 );
LD_WriteReg(0x08, 0x04);
delay(1);
LD_WriteReg(0x08, 0x00);
delay(1);
for (nAsrAddLength=0; nAsrAddLength<20;
nAsrAddLength++)
{
if (sRecog[k][nAsrAddLength] == 0)
break;
LD_WriteReg(0x5, sRecog[k][nAsrAddLength]);
}
LD_WriteReg(0xb9, nAsrAddLength);
LD_WriteReg(0xb2, 0xff);
LD_WriteReg(0x37, 0x04);
}
return flag;
}
uint8 LD_AsrRun(void)
{
LD_WriteReg(0x35,MIC_VOL);
LD_WriteReg(0x1C,0x09);
LD_WriteReg(0xBD,0x20);
LD_WriteReg(0x08,0x01);
delay( 1 );
LD_WriteReg(0x08,0x00);
delay( 1 );
if(LD_Check_ASRBusyFlag_b2() == 0)
{
return 0;
}
LD_WriteReg(0xB2, 0xff);
LD_WriteReg(0x37,0x06);
delay(5);
LD_WriteReg(0x1C,0x0b);
LD_WriteReg(0x29,0x10);
LD_WriteReg(0xBD,0x00);
EX0=1;
return 1;
}
uint8 RunASR(void)
{
uint8 i=0;
uint8 asrflag=0;
for (i=0; i<5; i++)
{
LD_Init_ASR();
delay(100);
if (LD_AsrAddFixed()==0)
{
LD_reset();
delay(100);
continue;
}
delay(10);
if (LD_AsrRun() == 0)
{
LD_reset();
delay(100);
continue;
}
asrflag=1;
break;
}
return asrflag;
}
uint8 LD_GetResult()
{
return LD_ReadReg(0xc5 );
}
void mucinit()
{
P2M1=0X00;
P2M0=0XFF;
P3M1=0XFA;
P3M0=0XFF;
IT0=1;
EX0=1;
EA=1;

}
void ProcessInt0()
{
uint8 nAsrResCount=0;
uint8 ucRegVal;
EX0=0;
ucRegVal = LD_ReadReg(0x2B);
if(nLD_Mode == LD_MODE_ASR_RUN)
{
// 语音识别产生的中断
// (有声音输入,不论识别成功或失败都有中断)
LD_WriteReg(0x29,0) ;
LD_WriteReg(0x02,0) ;
if((ucRegVal & 0x10) &&
LD_ReadReg(0xb2)==0x21 &&
LD_ReadReg(0xbf)==0x35)
{
nAsrResCount = LD_ReadReg(0xba);
if(nAsrResCount>0 && nAsrResCount<=4)
{
nAsrStatus=LD_ASR_FOUNDOK;
}
else
{
nAsrStatus=LD_ASR_FOUNDZERO;
}

}
else
{
nAsrStatus=LD_ASR_FOUNDZERO;
}

    LD_WriteReg(0x2b, 0);
    LD_WriteReg(0x1C,0);
     ET0=1;
    return;
}

}
void ExtInt0Handler() interrupt 0
{
ProcessInt0();
}
void main()
{

uint8 nAsrRes;
mucinit();

LD_reset();
nAsrStatus = LD_ASR_NONE; // 初始状态:没有在作ASR

    switch(nAsrStatus)
    {
        case LD_ASR_RUNING:
        case LD_ASR_ERROR:      
            break;
        case LD_ASR_NONE:
        {
            nAsrStatus=LD_ASR_RUNING;
            if (RunASR()==0)    //  启动一次ASR识别流程:ASR初始化,ASR添加关键词语,启动ASR运算
            {
                nAsrStatus = LD_ASR_ERROR;
            }
            break;
        }
        case LD_ASR_FOUNDOK:
        {
            nAsrRes = LD_GetResult();   //  一次ASR识别流程结束,去取ASR识别结果
            if(nAsrRes==1)
                {
                while(1)
                {
                   out_1=1;
                   out_2=0;
                   gu=1;
                   }
                }
            if(nAsrRes==2)
                {
                   out_3=1;
                   out_4=0;
                   gu=2;
                }
            if(nAsrRes==3)
                {
                   out_5=1;
                   out_6=0;
                   gu=3;
                }
            if(nAsrRes==4)
                {
                   out_7=1;
                   out_8=0;
                   gu=4;
                }
            if(nAsrRes==0)
            {
                if(gu==1)
                 {      
                  out_1=0;
                  out_2=1;
                 }
                 if(gu==2)
                 {       
                  out_3=0;
                  out_4=1;
                 }
                 if(gu==3)
                 {
                  out_5=0;
                  out_6=1;
                 }
                  if(gu==4)
                 {
                  out_7=0;
                  out_8=1;
                 }      
            }
            nAsrStatus = LD_ASR_NONE;
            break;
        }
        case LD_ASR_FOUNDZERO:

             break;
        default:
        {
            nAsrStatus = LD_ASR_NONE;
            break;
        }
    }// switch
}// while

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问