while(1)
{
BSR();
if((*P_IOA_Data)&0x0004) //是否重新训练
{
F_FlashErase(0xe000);
while(1);
}
}
}
(2)实现延时功能的程序
Void Delay()
{
unsigned int i;
for(i=0;i<0x3ff;i++)
{
*P_Watchdog_Clear=0x0001;
}
}
(3)实现语音播放的程序
void PlaySnd(unsigned SndIndex,unsigned DAC_Channel)
{
BSR_StopRecognizer(); //停止识别器
SACM_S480_Initial(1); //初始化为自动播放
SACM_S480_Play(SndIndex, DAC_Channel, 3);//开始播放一段语音
while((SACM_S480_Status()&0x0001)!= 0) //是否播放完毕?
{
SACM_S480_ServiceLoop(); //解码并填充队列
*P_Watchdog_Clear=0x0001; //清看门狗
}
SACM_S480_Stop(); //停止播放
BSR_InitRecognizer(BSR_MIC); //初始化识别器
}
(4)实现训练一条指令的程序
int TrainWord(unsigned int WordID,unsigned int SndID)
{
int Result;
PlaySnd(SndID,3); //引导训练,播放指令对应动作
while(1)
{
Result = BSR_Train(WordID,BSR_TRAIN_TWICE); //训练两次,获得训练结果
if(Result==0)break;
switch(Result)
{
case -1: //没有检测出声音
PlaySnd(S_NOVOICE,3);
return -1;
case -2: //需要训练第二次
PlaySnd(S_AGAIN,3);
break;
case -3: //环境太吵
PlaySnd(S_NOISY,3);
return -3;
case -4: //数据库满
return -4;
case -5: //检测出声音不同
PlaySnd(S_CMDDIFF,3);
return -5;
case -6: //序号错误 SPCE061A语音控制小车设计+源代码(8):http://www.751com.cn/tongxin/lunwen_1001.html