基于单片机的语音控制小车毕业设计论文

华科学院本科毕业设计(论文)

附 录

附1

主要程序:

工程名称: Car_Demo 涉及的库: CMacro1016.lib bsrv222SDL.lib sacmv26e.lib 组成文件:main.c

Flash.asm, hardware.asm,ISR.asm hardware.h,s480.h, hardware.inc 硬件连接:IOA0-----KEY1 IOA1-----KEY2 IOA2-----KEY3 IOB8-----前进 IOB9-----倒车 IOB10----左拐 IOB11----右拐

#include \#include \

#define P_IOA_Data #define P_IOA_Dir

(volatile unsigned int *)0x7000 (volatile unsigned int *)0x7002 (volatile unsigned int *)0x7003 (volatile unsigned int *)0x7005 (volatile unsigned int *)0x7007 (volatile unsigned int *)0x7008 (volatile unsigned int *)0x700A

- 47 -

#define P_IOA_Attrib #define P_IOB_Data #define P_IOB_Dir #define P_IOB_Attrib

#define P_TimerA_Data

康虹:基于单片机的语言控制小车设计

#define P_TimerA_Ctrl #define P_TimerB_Data #define P_TimerB_Ctrl

(volatile unsigned int *)0x700B (volatile unsigned int *)0x700C (volatile unsigned int *)0x700D

#define P_Watchdog_Clear (volatile unsigned int *)0x7012 #define P_INT_Mask #define P_INT_Clear #define NAME_ID

(volatile unsigned int *)0x702D (volatile unsigned int *)0x7011

0x100

0x101

#define COMMAND_GO_ID

#define COMMAND_BACK_ID 0x102 #define COMMAND_LEFT_ID 0x103 #define COMMAND_RIGHT_ID 0x104

#define S_NAME #define S_ACT1 #define S_ACT2 #define S_ACT3 #define S_ACT4 #define S_RDY

0

//给我取个名字吧

1 //前进 2 3

//倒车,请注意 //左拐

4 //右拐 5

//Yeah

#define S_AGAIN 6 //请再说一遍

#define S_NOVOICE 7 //没有听到任何声音 #define S_CMDDIFF #define S_NOISY #define S_START #define S_GJG

8 8

//说什么暗语呀 //说什么暗语呀

9

//准备就绪,开始辨识

//拐就拐 //倒车,请注意

10 11

#define S_DCZY

extern unsigned int BSR_SDModel[100]; //外部变量辨识器自带 extern void F_FlashWrite1Word(unsigned int addr,unsigned int Value); extern void F_FlashErase(unsigned int sector);

unsigned int uiTimeset = 3;//运行时间定时,调整该参数控制运行时间 unsigned int uiTimecont; //运行时间计时

- 48 -

华科学院本科毕业设计(论文)

//语法格式: void Delay(); // 实现功能: // 参数:

延时

// 返回值: void Delay() {

unsigned int i; for(i=0;i<0x3Fff;i++) {

*P_Watchdog_Clear=0x0001; } }

语法格式: void PlaySnd(unsigned SndIndex,unsigned DAC_Channel); // 实现功能:

语音播放函数

// 参数: SndIndex-播放语音资源索引号 //

DAC_Channel-播放声道选择

// 返回值:

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); }

int TrainWord(unsigned int WordID,unsigned int SndID)

- 49 -

康虹:基于单片机的语言控制小车设计

{

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: return -6; default: break; }

return 0;

- 50 -

//序号错误

}

华科学院本科毕业设计(论文)

// 语法格式: void TrainSD();// 实现功能: 训练函数

// 参数:

// 返回值: 无

void TrainSD() {

while(TrainWord(NAME_ID,S_NAME) != 0) ; //训练名称

while(TrainWord(COMMAND_GO_ID,S_ACT1) != 0) ; //训练第1个动作 while(TrainWord(COMMAND_BACK_ID,S_ACT2) != 0) ; //训练第2个动作 while(TrainWord(COMMAND_LEFT_ID,S_ACT3) != 0) ; //训练第3个动作 while(TrainWord(COMMAND_RIGHT_ID,S_ACT4) != 0) ;//训练第4个动作 }

语法格式: void StoreSD(); // 实现功能: 存储语音模型函数

// 参数:

// 返回值:

void StoreSD()

{ unsigned int ulAddr,i,commandID,g_Ret; F_FlashWrite1Word(0xef00,0xaaaa); F_FlashErase(0xe000); F_FlashErase(0xe100); F_FlashErase(0xe200); ulAddr=0xe000;//********

for(commandID=0x100;commandID<0x105;commandID++) { g_Ret=BSR_ExportSDWord(commandID);

while(g_Ret!=0)

//模型导出成功? g_Ret=BSR_ExportSDWord(commandID);

for(i=0;i<100;i++)

//保存语音SD1(0xe000---0xe063)

{

- 51 -

模型

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4