硬件平臺(tái)
stm32f103c8t6,LD-V7語(yǔ)音識(shí)別模塊
語(yǔ)音模塊介紹
重點(diǎn)?。?/p>
串口通信
語(yǔ)音模塊串口發(fā)送的內(nèi)容(被修改了,不是出廠內(nèi)容,修改步驟看資料)
switch(dat) /*對(duì)結(jié)果執(zhí)行相關(guān)操作,客戶可刪除Printcom 串口輸出語(yǔ)句替換為其他需要控制的代碼*/
{
case CODE_DMCS: /*命令“亮一點(diǎn)”*/
PrintCom("亮一點(diǎn)rn"); /*text.....*/
break;
case CODE_KFBYZ: /*命令“變暗”*/
PrintCom("變暗rn"); /*text.....*/
break;
case CODE_KD: /*命令“開燈”*/
PrintCom("開燈rn"); /*text.....*/
break;
case CODE_GD: /*命令“關(guān)燈”*/
PrintCom("關(guān)燈rn"); /*text.....*/
break;
case CODE_BJ: /*命令“亮度30”*/
PrintCom("亮度30rn"); /*text.....*/
break;
case CODE_SH: /*命令“亮度60”*/
PrintCom("亮度60rn"); /*text.....*/
break;
case CODE_GZ: /*命令“亮度100”*/
PrintCom("亮度100rn"); /*text.....*/
break;
default:PrintCom("請(qǐng)重新識(shí)別發(fā)口令rn"); /*text.....*/break;
}
}
else
{
PrintCom("請(qǐng)說(shuō)出一級(jí)口令rn"); /*text.....*/
}
STM32C8T6接收
主要分為串口中斷,超時(shí)方式接收,比較
超時(shí)方式接收被放到了主循環(huán),配合串口中斷使用,是一個(gè)不太成熟的函數(shù),不過(guò)用在這里綽綽有余。
//串口中斷函數(shù):
u8 rev_buf[100];//接收緩沖區(qū)
u8 addr=0; //地址偏移量
u8 revice_ok=0;//接收完成標(biāo)志
u8 revice_start=0;//開始接收受標(biāo)志
u32 time_out=0;//超時(shí)計(jì)數(shù)值
//串口1中斷服務(wù)函數(shù)
void USART1_IRQHandler(void)
{
u8 data;
data=USART1->DR;//讀取同時(shí)會(huì)清除標(biāo)志
rev_buf[addr++]=data;
//printf("addr:%drn",addr);
revice_start=1;//開始接收
time_out=0;//超級(jí)計(jì)數(shù)值清零
}
//串口中斷接收函數(shù)
int ld3320_uart_receive(void)
{
//char * buf = NULL;
int num = 0;
if(revice_ok)
{
revice_ok=0;//清標(biāo)志
printf("%srn",rev_buf);
printf("%srn",rev_buf);
printf("rev_buf is ok rn");
num = compare_usart((char *) rev_buf);
return num;
}
if(revice_start)//開始接收
{
Main_delay();
time_out++;
num=0;
if(time_out>=50)//超時(shí)就
{
revice_ok=1;
rev_buf[addr]='?';
addr=0;
time_out=0;
revice_start=0;
}
}
return 0;
}
//比較
/*
對(duì)比的BUF是直接定好的,宏定義方便使用
#define BUF_XIAOCHEN "收到rn"
#define BUF_LIANG "亮一點(diǎn)rn"
#define BUF_AN "變暗rn"
#define BUF_KAI "開燈rn"
#define BUF_GUAN "關(guān)燈rn"
#define BUF_SANSHI "亮度30rn"
#define BUF_LIUSHI "亮度60rn"
#define BUF_YIBAI "亮度100rn"
#define BUF_CONGFA "請(qǐng)重新識(shí)別發(fā)口令rn"
#define BUF_FA "請(qǐng)說(shuō)出一級(jí)口令rn"
*/
int compare_usart(char * string_data)
{
if(strcmp(string_data, ( char *)BUF_XIAOCHEN) == 0) //比較接受字符內(nèi)容 收到
{
printf("this is compare return 1rn");
return 1;
}
else if(strcmp((char *)rev_buf, (char *)BUF_LIANG) == 0)
{
return 2;
}
else if(strcmp((char *)rev_buf, (char *)BUF_AN) == 0)
{
return 3;
}
else if(strcmp((char *)rev_buf, (char *)BUF_KAI) == 0)
{
return 4;
}
else if(strcmp((char *)rev_buf, (char *)BUF_GUAN) == 0)
{
return 5;
}
else if(strcmp((char *)rev_buf, (char *)BUF_SANSHI) == 0)
{
return 6;
}
else if(strcmp((char *)rev_buf, (char *)BUF_LIUSHI) == 0)
{
return 7;
}
else if(strcmp((char *)rev_buf, (char *)BUF_YIBAI) == 0)
{
return 8;
}
else if(strcmp((char *)rev_buf, (char *)BUF_CONGFA) == 0)
{
return 9;
}
else if(strcmp((char *)rev_buf, (char *)BUF_FA) == 0)
{
return 10;
}
return 0;
}
經(jīng)過(guò)這三步,就可以在主循環(huán)得到返回值,根據(jù)返回?cái)?shù)值執(zhí)行對(duì)應(yīng)操作。
j=ld3320_uart_receive();//得到接受函數(shù)的字符串buff
//i=compare_usart(buff); //字符串buff和已知字符串對(duì)比的值
//i=1;
printf("j = %drn",j);
switch(j)
{
case 1:
//printf("1rn");
OLED_ShowChar(48,6,1);
//OLED_Clear();
break;//小陳
case 2: printf(" switch :2rn");break;//亮一點(diǎn)
case 3: printf(" switch :3rn");break;//變暗
case 4: printf(" switch :4rn");break;//開燈
case 5: printf(" switch :5rn");break;//關(guān)燈
case 6: printf(" switch :6rn");break;//
case 7: printf(" switch :7rn");break;//
case 8: printf(" switch :8rn");break;//
case 9: printf(" switch :9rn");break;//請(qǐng)重新識(shí)別發(fā)口令
case 10: printf(" switch :10rn");break;//請(qǐng)說(shuō)出一級(jí)口令
//case 11: printf("11rn");break;//
default:break;
}
}
閱讀全文