- #include "system.h"
- #include "SysTick.h"
- #include "led.h"
- #include "usart.h"
- #include "string.h"
- void kaishishibie()
- {
- char sbuf[]={0xD4,0xDA,0xE0,0xCF,0x21};
- u16 i=0;
- char len;
- char head[8];
- len=strlen(sbuf);
- head[0]=0xFD;
- head[1]=0x00;
- head[2]=len+2;
- head[3]=0x15;//语音识别模式
- head[4]=0x03;//词典库
- head[5]=0x09;//唤醒名称
- head[6]=0x01;
- head[7]=0x01;
- for (i=0;i<8;i++)
- {
- USART_SendData(USART3,head[i]);
- while(USART_GetFlagStatus(USART3,USART_FLAG_TXE) != SET);
- }
- for (i=0;i<len;i++)
- {
- USART_SendData(USART3,sbuf[i]);
- while(USART_GetFlagStatus(USART3,USART_FLAG_TXE) != SET);
- }
- }
- void delay_nms(u16 time)
- { u16 i=0;
- while(time--)
- {
- i=12000;
- while(i--) ;
- }
- }
- int main()
- {
- u8 state=0,ml=0;
- USART3_Init(115200);
- SysTick_Init(72);
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- LED_Init();
- led1=0;
- led2=0;
- led3=0;
- while (1)
- {
- kaishishibie();
- q=0;
- while (1)
- {
- if(q==1)
- {
- q=0;
- if(bufer[2]==0x01)
- {
- switch (bufer[3])
- {
- case 0x4A:state=0;break;//模块初始化成功回传
- case 0x41:state=0;break;//接收到正确的命令帧回传
- case 0x45:state=1;break;//接收失败,收到不能识别的命令帧
- case 0x4F:state=1;break;//模块空闲状态回传
- case 0x42:state=0;break;//处于语音识别或者语音唤醒状态
- case 0x49:state=0;break;//处于MP3播放
- case 0x4B:state=0;break;//更新词典
- case 0x4E:state=0;break;//语音合成播放
- case 0x21:state=0;break;//唤醒成功
- case 0x22:state=0;break;//唤醒内部错误
- case 0x23:state=0;break;//自定义唤醒名称设置成功
- case 0x24:state=0;break;//自定义唤醒名称设置失败
- case 0x31:state=1;break;//词典更新成功
- case 0x32:state=1;break;//词典更新失败
- case 0x03:state=1;break;//用户静音超时
- case 0x04:state=1;break;//用户语音超时
- case 0x05:state=1;break;//识别拒识
- case 0x06:state=1;break;//识别拒识
- case 0x07:state=1;break;//识别内部错误
- case 0x99:state=1;break;//查询模块版本回传
- }
- }
- else if(bufer[4]==0x06)
- {
- state=1;//识别成功,带命令ID
- ml=bufer[8];//将命令ID给ML
- }
- else if(bufer[4]==0x04)
- {
- state=1;//识别成功,无命令ID
- }
- if(state==1)
- {
- break;
- }
- }
- switch(ml)
- {
- case 1:led4=0;led6=1;break;
- case 2:led4=1;led6=1;break;
- case 3:led5=0;led6=1;break;
- case 4:led5=1;led6=1;break;
- default :led6=0;
- }
- }
- memset(bufer,0,sizeof (bufer));
- }
- }
复制代码
全部资料51hei下载地址:
语音识别.7z
(176.94 KB, 下载次数: 18)
|