语音模块LD3320控制小车运动

原理:
利用LD3320模块控制小车运动,小车驱动模块为L298N,语音模块采用LD3320。LD3320内核为51单片机,将识别的状态通过串口发送STM32,利用STM32控制小车运动。
实验现象:
(1)语音“前进”,小车前进;
(2)语音“后退”,小车后退;
(3)语音“停止”,小车停止;
(4)语音“左转”,小车左转;
(5)语音“右转”,小车右转;
(6)语音“跳舞”,小车跳舞 。
视频演示
https://www.bilibili.com/video/bv1H7411m7x9

源程序下载地址
程序中包含的文件
LD3320语音程序与STM32小车控制程序
硬件连接图
语音模块LD3320控制小车运动_第1张图片
LD3320部分程序:
关键词程序:

uint8 LD_AsrAddFixed()
{
  uint8 k, flag;
  uint8 nAsrAddLength;
#define DATE_A 11   /*数组二维数值*/
#define DATE_B 20   /*数组一维数值*/
  uint8 code sRecog[DATE_A][DATE_B] =
  {
    "xiao long",\
    "qian jin",\
    "hou ",\
    "ting zhi",\
    "zuo zhuan",\
    "you zhuan",\
    "tiao wu",\
    "kai deng",\
    "guan deng",\
  };

执行程序:

void   User_handle(uint8 dat)
{  if(0==dat)
  {    G0_flag=ENABLE; LED=0;
  }
  else if(ENABLE==G0_flag)
  {    G0_flag=DISABLE;
        LED=1;
      switch(dat) 	
{
case CODE_1:         /*forward*/		
UARTSendByte(0x01);     PrintCom("1cat go\r\n");      break;
case CODE_2:        /*backword*/		
UARTSendByte(0x02);    PrintCom("2cat back\r\n");     break;
case CODE_3:        /*stop*/
UARTSendByte(0x03);   PrintCom("3cat stop\r\n");     break;
case CODE_4:        /*left*/			
UARTSendByte(0x04);  PrintCom("4cat left\r\n");     break;
case CODE_5:       /*right*/
UARTSendByte(0x05);    PrintCom("5cat right\r\n");     break;
case CODE_6:        /*dance*/
UARTSendByte(0x06);    PrintCom("6cat dance\r\n");     break;
case CODE_7:        /*turn on*/
UARTSendByte(0x07);    PrintCom("7turn on\r\n");     break;
case CODE_8:     /*turn off*/
UARTSendByte(0x08);    PrintCom("8turn off\r\n");     break;
default:/*text.....*/
break;
}
  }
  else
  {    PrintCom("请说出一级口令\r\n"); /*text.....*/   }
}

STM32主程序:

#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "motor.h"
#include "pwm.h"
int main(void)
{  vu8 key=0;	  u8 len=0;	  u8 get=0;
    HAL_Init();                    	//初始化HAL库    
    Stm32_Clock_Init(RCC_PLL_MUL9); //设置时钟,72M
    delay_init(72);                 //初始化延时函数
   LED_Init();                     //初始化LED 
   MOTOR_Init();                   //初始化电机端口
   uart_init(9600);
   uart3_init(9600);
   TIM3_PWM_Init(899,0
   LED0=0;	
  while(1)
  {   if(USART3_RX_STA&0x8000)
     {     len=USART3_RX_STA&0x3fff;
get=USART3_RX_BUF[0];  printf("\r\n\r\ncode is %d\r\n", get);
switch(get)
{
case 1: {DirForward(480);} break;
case 2: {DirBack(480);} break;
case 3: {Stop();} break;
case 4: {Left(480,0);} break;
case 5: {Right(0,480);} break;
case 6: {Left(480,0);Right(0,480);DirForward(480);Left(480,0);Right(0,480);} break;
default: {LED0=1;LED1=1;}break;			
}
HAL_UART_Transmit(&UART3_Handler,(uint8_t*)USART3_RX_BUF,len,1000);
while(__HAL_UART_GET_FLAG(&UART3_Handler,UART_FLAG_TC)!=SET); 
USART3_RX_STA=0;
}   }   }

STM32串口输出程序
语音模块LD3320控制小车运动_第2张图片

你可能感兴趣的:(stm32,语音识别,串口通信)