📄 web.c
字号:
//======================================================================================
//
// The information contained herein is the exclusive property of
// Sunplus Technology Co. And shall not be distributed, reproduced,
// or disclosed in whole in part without prior written permission.
//
// (C) COPYRIGHT 2001 SUNPLUS TECHNOLOGY CO.
// ALL RIGHTS RESERVED
//
// The entire notice above must be reproduced on all authorized copies.
//
//========================================================================================
// 工程名称: Guard_SD.spj
// 功能描述: 该程序是特定人辨识的一个范例:
// 在程序中我们通过三条语句的训练演示特定人连续音识别,其中第一条语句为触发命令。
// 在程序一开始为训练名称,即触发命令,然后提示训练两条命令,训练完毕开始辨识当识别
// 出触发名称后,发布命令则会听到应答,具体命令如下:
//****************训练******************************************
// 提示音 输入语音
//--------------------------------------------------------
// "A同学" "到"
// "B同学" "到"
// "C同学" "到"
// "再说一遍"(以上提示音每说完一遍出现此命令)
// "没有声音"(当没有检测到声音时出现此命令)
// "开始辨识"(以上三条语句全部训练成功时,进入识别)
//*****************识别*****************************************
// 发布命令 应答
//---------------------------------------------------------
// "A同学" "到"
// "B同学" "到"
// "C同学" "到"
// 注意:在每次提示音结束后2-3秒再输入命令或当上次应答结束2-3秒后再发布命令
// 文件来源: 《SPCE061单片机原理及应用技术》第七章 凌阳音频压缩算法,第307页
// IDE环境: SUNPLUS u'nSPTM IDE 1.8.0(or later)
//
// 涉及的库: CMacro.lib/sacmv25.lib/bsrv222SDL.lib
//
// 组成文件: web.c
// FIQ.asm/hardware.asm/key.asm/InitIO.asm
// hardware.inc
//
// 日期:
//===========================================================================================
#include "bsrsd.h"
#include "SPCE061V004.H"
#define NAME_A 0x100//A到
#define NAME_B 0x101
#define NAME_C 0x102
#define RSP_A 1//A同学
#define RSP_B 2
#define RSP_C 3
#define RSP_INTR 0//开始训练
#define RSP_AGAIN 4//
#define RSP_NOVOICE 5//
#define RSP_NOISY 7//
#define RSP_STAR 6//开始识别
//.......全程变量.......
int gActivated = 0; //该变量用于检测是否有触发命令
int gTriggerRespond[] = {RSP_A, RSP_B, RSP_C};//
extern void WatchDog_Clear();
int PlayFlag = 0;
//........playRespond.......
void PlayRespond(int Result)
{
BSR_StopRecognizer();
SACM_S480_Initial(1);
SACM_S480_Play(Result, 3, 3);
while((SACM_S480_Status()&0x0001) != 0)
{
SACM_S480_ServiceLoop();
*P_Watchdog_Clear=1;
}
SACM_S480_Stop();
BSR_InitRecognizer(BSR_MIC);
BSR_EnableCPUIndicator();
}
//.......trainword.......
int TrainWord(int WordID, int RespondID)
{
int res;
PlayRespond(RespondID);
while(1)
{
res = BSR_Train(WordID,BSR_TRAIN_TWICE);
if(res == 0) break;
switch(res)
{
case -1: //没有检测出声音
PlayRespond(RSP_NOVOICE);
return -1;
case -2: //需要重新训练一遍
PlayRespond(RSP_AGAIN);
break;
case -3: //环境太吵
PlayRespond(RSP_NOISY);
return -1;
case -4: //数据库满
return -1;
case -5: //检测出声音不同
return -1;
case -6: //序号错误
return -1;
}
}
return 0;
}
//.......recognise.......
unsigned int recognise()
{ BSR_InitRecognizer(BSR_MIC); //辨识器初始化
BSR_EnableCPUIndicator();
PlayRespond(RSP_STAR); // 播放开始辨识的提示音
while(1)
{
int res = BSR_GetResult();
int timeCnt = 0;
if(res > 0) //识别出命令
{
if(gActivated)
{
switch(res)
{
case NAME_A:
return 1;
case NAME_B:
gActivated = 0;
return 2;
case NAME_C:
gActivated = 0;
return 3;
default:
return 0;
}
}
else
{
if(res == NAME_A)
{
gActivated = 1;
timeCnt = 0;
return 1;
}
}
}
else if (gActivated)
{
if (++timeCnt > 450) //超出定时
{
PlayRespond(RSP_NOVOICE); //在设定时间内没有检测出声音
gActivated = 0;
timeCnt = 0;
return 0;
}
}
}
}
//.......web........
void web()
{
unsigned int uiData , uoData,Ret; //接收发送的数据
unsigned int jieguo; //
*P_IOB_Dir=0x0480; //IOB7,IOB10初始化
*P_IOB_Attrib=0x0400;
*P_IOB_Data=0x0000;
*P_UART_Command1=0x20; //Uart内部复位
*P_UART_Command1=0x00;
*P_UART_BaudScalarHigh=0x00; //波特率设置为115200bps
*P_UART_BaudScalarLow=0x6B;
*P_UART_Command1=0x000C; //允许接收
*P_UART_Command2=0x00C0;
Ret=*P_UART_Data; // 清接收缓冲区
while(1) //接收循环
{
Ret=*P_UART_Command2;
Ret=Ret&0x0080;
while(Ret==0) //等待接收完毕
{
Ret=*P_UART_Command2;
Ret=Ret&0x0080;
*P_Watchdog_Clear=C_WDTCLR;
}
uiData=*P_UART_Data; //读出接收的数据
while(uiData==1|uiData==2|uiData==3) //接收完毕处理:发送结果
{
unsigned int m=uiData-1;
PlayRespond(gTriggerRespond[m]); //播放名字
jieguo=recognise(); //识别
if(jieguo==uiData) //识别与点名匹配
{ //发送
*P_UART_Command1=0x000C; //允许发送
*P_UART_Command2=0x00C0;
Ret=*P_UART_Data; // 清发送缓冲区
while(1)
{
Ret=*P_UART_Command2;
Ret=Ret&0x0080;
while(Ret==0) //等待发送完毕
{
Ret=*P_UART_Command2;
Ret=Ret&0x0080;
*P_Watchdog_Clear=C_WDTCLR;
}
}
}
}
}
}
//........main........
void main()
{
BSR_DeleteSDGroup(0); // 初始化存储器RAM
PlayRespond(RSP_INTR); //播放开始训练的提示音
while(TrainWord(NAME_A,1) != 0) ; //训练
while(TrainWord(NAME_B,2) != 0) ;
while(TrainWord(NAME_C,3) != 0) ;
///////////////////////////////////////////////////////////////////
//UART传入-点名-识别-返回统计结果-UART传出
///////////////////////////////////////////////////////////////////
web();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -