RT系统+STM32+SYN8266播报+红外定时器

老规矩,先上产品图

 实验材料 :

stm32f103c8t6+syn8266+红外传感器

实验平台:

keil + RT系统

主要附上如何配置SYN8266

syn8266.h

#ifndef _SYN6288_H_
#define _SYN6288_H_
#include "stm32f10x.h"
#include <stdio.h>
#include <stdbool.h>



#if defined ( __CC_ARM   )
#pragma anon_unions
#endif
/******************************* ESP8266 外部全局变量声明 ***************************/
#define RX_BUF_MAX_LEN     1024                                     //最大接收缓存字节数

extern struct  STRUCT_USARTx_Fram                                  //串口数据帧的处理结构体
{
	char  Data_RX_BUF [ RX_BUF_MAX_LEN ];
	
  union {
    __IO u16 InfAll;
    struct {
		  __IO u16 FramLength       :15;                               // 14:0 
		  __IO u16 FramFinishFlag   :1;                                // 15 
	  } InfBit;
  }; 
	
} strUSART_Fram_Record;




/* 开发板硬件相关头文件 */

/**  
  ******************************************************************************
  *  @File     SYN6288.h
  *  @Author   Velscode  
  *  @Email    velscode@gmail.com
  *  @Brief    TTS 芯片 SYN6288驱动头文件(基于STM32F10x)
  *            使用了USART2(A2\A3)
  ******************************************************************************
  */

//extern struct STRUCT_USARTx_Fram strUSART_Fram_Record;	
	/****************************** SYN6288 引脚配置参数定义***************************************/
#define             SYN6288_GPIO_APBxClock_FUN              RCC_APB2PeriphClockCmd
#define             SYN6288_GPIO_CLK                        RCC_APB2Periph_GPIOB
#define             SYN6288_GPIO_PORT                       GPIOB
#define             SYN6288_GPIO_PIN                        GPIO_Pin_2
#define      				SYN6288_Read_GPIO_IN()	                GPIO_ReadInputDataBit ( SYN6288_GPIO_PORT, SYN6288_GPIO_PIN ) 

// 串口2-USART2
#define  DEBUG_USART_SYN6288                    USART3
#define  DEBUG_USART_CLK_SYN6288                 RCC_APB1Periph_USART3
#define  DEBUG_USART_APBxClkCmd_SYN6288          RCC_APB1PeriphClockCmd
#define  DEBUG_USART_BAUDRATE           9600

// USART GPIO 引脚宏定义
#define  DEBUG_USART_GPIO_CLK_SYN6288            (RCC_APB2Periph_GPIOB)
#define  DEBUG_USART_GPIO_APBxClkCmd    RCC_APB2PeriphClockCmd
    
#define  DEBUG_USART_TX_GPIO_PORT_SYN6288        GPIOB   
#define  DEBUG_USART_TX_GPIO_PIN_SYN6288         GPIO_Pin_10
#define  DEBUG_USART_RX_GPIO_PORT_SYN6288        GPIOB
#define  DEBUG_USART_RX_GPIO_PIN_SYN6288         GPIO_Pin_11

#define  DEBUG_USART_IRQ_SYN6288                 USART3_IRQn
#define  DEBUG_USART_IRQHandler_SYN6288          USART3_IRQHandler



void SYN6288_GPIO_Config ( void );
void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch);
void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str );
void SYN688_USART_Config(void);
void Usart_SYN6288_SendByte( USART_TypeDef * pUSARTx, uint8_t ch);
void SYN_FrameInfo(char *HZdata);
void Usart_SSYN6288_endString( USART_TypeDef * pUSARTx, char *str);
/* 音量控制 */
void Volinme(uint8_t Y_L);
/* 语调控制 */
void Intonation(uint8_t Y_L);
/* 语速控制 */
void Speed_pacing(uint8_t Y_L);
/* 人控制 */
void speed_man(uint8_t Y_L);
#endif /*_SYN6288_H_*/
/* End of File ------------------------------------------------------------- */



syn8266.c

/**
******************************************************************************
*  @File     SYN6288.c
*  @Author   Velscode  
*  @Email    velscode@gmail.com
*  @Brief    TTS 芯片 SYN6288驱动源代码文件(基于STM32F10x)
*            使用了USART2(A2\A3)
******************************************************************************
*/

/* Internal Function Declaration ------------------------------------------- */
void usart2_Init(unsigned int bound);

/* Header Files ------------------------------------------------------------ */
#include "SYN6288.h"
#include "string.h"
/* RT-Thread相关头文件 */
#include <rthw.h>
#include <rtthread.h>
#include <string.h>
struct  STRUCT_USARTx_Fram strUSART_Fram_Record = { 0 };

 /**
  * @brief  配置嵌套向量中断控制器NVIC
  * @param  无
  * @retval 无
  */
static void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* 嵌套向量中断控制器组选择 */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  
  /* 配置USART为中断源 */
  NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ_SYN6288;
  /* 抢断优先级*/
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  /* 子优先级 */
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  /* 使能中断 */
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  /* 初始化配置NVIC */
  NVIC_Init(&NVIC_InitStructure);
}
//读忙
void SYN6288_GPIO_Config ( void )
{		
	/*定义一个GPIO_InitTypeDef类型的结构体*/
	GPIO_InitTypeDef GPIO_InitStructure;


	/* 配置 LED1 引脚 */
	SYN6288_GPIO_APBxClock_FUN(SYN6288_GPIO_CLK, ENABLE); 															   
	GPIO_InitStructure.GPIO_Pin = SYN6288_GPIO_PIN;	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
	GPIO_Init ( SYN6288_GPIO_PORT, & GPIO_InitStructure );	
	
}

 /**
  * @brief  USART GPIO 配置,工作参数配置
  * @param  无
  * @retval 无
  */
void SYN688_USART_Config(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;

	// 打开串口GPIO的时钟
	DEBUG_USART_GPIO_APBxClkCmd(DEBUG_USART_GPIO_CLK_SYN6288, ENABLE);
	
	// 打开串口外设的时钟
	DEBUG_USART_APBxClkCmd_SYN6288(DEBUG_USART_CLK_SYN6288, ENABLE);

	// 将USART Tx的GPIO配置为推挽复用模式
	GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_GPIO_PIN_SYN6288;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(DEBUG_USART_TX_GPIO_PORT_SYN6288, &GPIO_InitStructure);

  // 将USART Rx的GPIO配置为浮空输入模式
	GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_GPIO_PIN_SYN6288;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(DEBUG_USART_RX_GPIO_PORT_SYN6288, &GPIO_InitStructure);
	
	// 配置串口的工作参数
	// 配置波特率
	USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
	// 配置 针数据字长
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	// 配置停止位
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	// 配置校验位
	USART_InitStructure.USART_Parity = USART_Parity_No ;
	// 配置硬件流控制
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	// 配置工作模式,收发一起
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	// 完成串口的初始化配置
	USART_Init(DEBUG_USART_SYN6288, &USART_InitStructure);
	
	// 串口中断优先级配置
	NVIC_Configuration();
	
	// 使能串口接收中断
	USART_ITConfig(DEBUG_USART_SYN6288, USART_IT_RXNE, ENABLE);	
	
	// 使能串口
	USART_Cmd(DEBUG_USART_SYN6288, ENABLE);		

  // 清除发送完成标志
	//USART_ClearFlag(USART1, USART_FLAG_TC);     
}
//其实是USART2_Send_Byte
/*****************  发送一个字符 **********************/
void Usart_SYN6288_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
{
	/* 发送一个字节数据到USART */
	USART_SendData(pUSARTx,ch);
		
	/* 等待发送数据寄存器为空 */
	while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);	
}
/*****************  发送字符串 **********************/
void Usart_SSYN6288_endString( USART_TypeDef * pUSARTx, char *str)
{
	unsigned int k=0;
  do 
  {
      Usart_SYN6288_SendByte( pUSARTx, *(str + k) );
      k++;
  } while(*(str + k)!='\0');
  
  /* 等待发送完成 */
  while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
  {}
}

//语音合成
void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str )
{
	
	if(SYN6288_Read_GPIO_IN()==Bit_RESET)/* x us后仍为高电平表示数据“1” */
	{

				char * p = str;
		int len = 0,check=0xFD,i;
		
		while( *p++ != 0 )
		{
				len++;
		
		}
		
		len+=3;
		
		Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
		
		Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,len / 256 );
		Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,len % 256 );
		check  = check ^ ( len / 256 ) ^ ( len % 256 );
		
		Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,0x01 );
		Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,0x01 );
		check = check ^ 0x01 ^ 0x01;
		
		for( i = 0; i < len-3; i++ )
		{
				Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,*str);
				check ^= ( *str );
				str++;
		}
		Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,check);   
				
		rt_thread_delay(150*len);	
	}	

}
/* 音量控制 */
void Volinme(uint8_t Y_L)
{
		uint8_t num ;
	num = Y_L+48;
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x76);
	//控制音量
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
	
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
//	uint8_t num[9] ;
//	
//	num[0] = 0xFD;
//	num[1] = 0x00;
//	num[2] = 0x06;
//	num[3] = 0x01;
//	num[4] = 0x01;
//	num[5] = 0x5B;
//	num[6] = 0x76;
//	//控制音量
//	num[7] = Y_L+48;
//	num[8] = 0x5D;
//	
//	Usart_SendByte(DEBUG_USARTx,num[8]);
}
/* 语调控制 */
void Intonation(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x74);
	//控制音量
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
	
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
	

}
/* 语速控制 */
void Speed_pacing(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x73);
	//控制音量
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
	
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
	
}
/* 人控制 */
void speed_man(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x07);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x6D);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x35);
	//控制音量
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
	
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
	
}
/* End of File ------------------------------------------------------------- */



stm32f10x_it.t添加中断函数

/* 该文件统一用于存放中断服务函数 */
#include "stm32f10x_it.h"
#include "SYN6288.h"
// 串口中断服务函数
void DEBUG_USART_IRQHandler_SYN6288(void)
{
  uint8_t ucCh;
	if ( USART_GetITStatus ( DEBUG_USART_SYN6288, USART_IT_RXNE ) != RESET )
	{
		ucCh  = USART_ReceiveData( DEBUG_USART_SYN6288 );
		
		if ( strUSART_Fram_Record .InfBit .FramLength < ( RX_BUF_MAX_LEN - 1 ) )                       //预留1个字节写结束符
			   strUSART_Fram_Record .Data_RX_BUF [ strUSART_Fram_Record .InfBit .FramLength ++ ]  = ucCh;

	}
	 	 
	if ( USART_GetITStatus( DEBUG_USART_SYN6288, USART_IT_IDLE ) == SET )                                         //数据帧接收完毕
	{
    strUSART_Fram_Record .InfBit .FramFinishFlag = 1;		
		
		ucCh = USART_ReceiveData( DEBUG_USART_SYN6288 );                                                              //由软件序列清除中断标志位(先读USART_SR,然后读USART_DR)	
  }	
}

初始化syn8266

//语音播报系统
	  SYN6288_GPIO_Config();
	  SYN688_USART_Config();

在主函数中使用

//APP2
static void APP2_thread_entry(void* parameter)
{		
	rt_uint8_t key=0;
	rt_uint8_t dispBuff[100];
	rt_uint8_t t=0;	
	rt_uint8_t *str=0;
	while(1)
	{

	  key=Remote_Scan();
			
		if(key)
		{	
		switch(key)
			{
				case 162:
						//1
						str= "· time 10min·";
						munite = 10;
						hour=0;		
						second=0;
				    SYN6288_Speech(DEBUG_USART_SYN6288,"定时十分钟");
				    
            break;
        
        case 98:
						//2					
					  str= "· time 20min·";
            munite = 20;
						hour=0;	
						second=0;
				    SYN6288_Speech(DEBUG_USART_SYN6288,"定时二十分钟");
            break;
        
        case 226://3
					 str= "· time 30min·";
					 munite = 30;
					hour=0;	
						second=0;
            SYN6288_Speech(DEBUG_USART_SYN6288,"定时三十分钟");
						break;
        
        case 34://4
					 str= "· time 40min·";
						munite = 40;
					  hour=0;	
				    second=0;
						SYN6288_Speech(DEBUG_USART_SYN6288,"定时四十分钟");
            break;
        
        case 2://5
					 str= "· time 50min·";
           munite = 50;
					 hour=0;
					 second=0;
					 SYN6288_Speech(DEBUG_USART_SYN6288,"定时五十分钟");
            break;
        
        case 194://6
					 str= "· time 60min·";
           munite = 60;
					hour=0;
					second=0;
					SYN6288_Speech(DEBUG_USART_SYN6288,"定时六十分钟");
            break;
        
        case 224://7
					 str= "· time 90min·";
					 hour = 1;
           munite = 30;
					 second=0;
				   SYN6288_Speech(DEBUG_USART_SYN6288,"定时一个半小时");
            break;
        
        case 168://8
					 str= "· time  2h ·";
           hour = 1;
					munite = 60;
					second=0;
					SYN6288_Speech(DEBUG_USART_SYN6288,"定时两个小时");
            break;
        
        case 144://9
					SYN6288_Speech(DEBUG_USART_SYN6288,"定时三个小时");
					 str= "· time  3h ·";
           hour = 2;
						munite = 60;
						second=0;
				   
            break;
        
        case 152:
					 str= "detected code 0";
            name();
					  
            break;
        
        case 104:
					 str= "detected code *";
           
            break;
        
        case 176:
					 str= "detected code #";
           
            break;
                
        case 24:
					 str= "detected code ↑";
          
            break;
                
        case 16:
					 str= "detected code ←";
            
            break;
        
        case 74:
					  str= "detected code ↓";
         
            break;
        
        case 90:
					  str= "detected code →";
            break;
        
        case 56:
            str= "detected code OK ";
            break;
        
        default:
					  str= "EMOURE";
         
            break;

			}
			Draw_Font16B(4,100,BRRED,str);	//显示SYMBOL
			key = 0;
//			uwRet = rt_thread_resume(APP3_thread);/* 恢复APP3线程! */
//			if(RT_EOK == uwRet)
//			{
//				rt_kprintf("恢复APP3线程成功!\n");
//			}
//			else
//			{
//				rt_kprintf("恢复APP3线程失败!失败代码:0x%lx\n",uwRet);
//			}
			
		}
		
	}

}

附上代码连接 红外+语音播报 

版权声明:本文为CSDN博主「HR_CMD」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/herui_2/article/details/121663379

老规矩,先上产品图

 实验材料 :

stm32f103c8t6+syn8266+红外传感器

实验平台:

keil + RT系统

主要附上如何配置SYN8266

syn8266.h

#ifndef _SYN6288_H_
#define _SYN6288_H_
#include "stm32f10x.h"
#include <stdio.h>
#include <stdbool.h>



#if defined ( __CC_ARM   )
#pragma anon_unions
#endif
/******************************* ESP8266 外部全局变量声明 ***************************/
#define RX_BUF_MAX_LEN     1024                                     //最大接收缓存字节数

extern struct  STRUCT_USARTx_Fram                                  //串口数据帧的处理结构体
{
	char  Data_RX_BUF [ RX_BUF_MAX_LEN ];
	
  union {
    __IO u16 InfAll;
    struct {
		  __IO u16 FramLength       :15;                               // 14:0 
		  __IO u16 FramFinishFlag   :1;                                // 15 
	  } InfBit;
  }; 
	
} strUSART_Fram_Record;




/* 开发板硬件相关头文件 */

/**  
  ******************************************************************************
  *  @File     SYN6288.h
  *  @Author   Velscode  
  *  @Email    velscode@gmail.com
  *  @Brief    TTS 芯片 SYN6288驱动头文件(基于STM32F10x)
  *            使用了USART2(A2\A3)
  ******************************************************************************
  */

//extern struct STRUCT_USARTx_Fram strUSART_Fram_Record;	
	/****************************** SYN6288 引脚配置参数定义***************************************/
#define             SYN6288_GPIO_APBxClock_FUN              RCC_APB2PeriphClockCmd
#define             SYN6288_GPIO_CLK                        RCC_APB2Periph_GPIOB
#define             SYN6288_GPIO_PORT                       GPIOB
#define             SYN6288_GPIO_PIN                        GPIO_Pin_2
#define      				SYN6288_Read_GPIO_IN()	                GPIO_ReadInputDataBit ( SYN6288_GPIO_PORT, SYN6288_GPIO_PIN ) 

// 串口2-USART2
#define  DEBUG_USART_SYN6288                    USART3
#define  DEBUG_USART_CLK_SYN6288                 RCC_APB1Periph_USART3
#define  DEBUG_USART_APBxClkCmd_SYN6288          RCC_APB1PeriphClockCmd
#define  DEBUG_USART_BAUDRATE           9600

// USART GPIO 引脚宏定义
#define  DEBUG_USART_GPIO_CLK_SYN6288            (RCC_APB2Periph_GPIOB)
#define  DEBUG_USART_GPIO_APBxClkCmd    RCC_APB2PeriphClockCmd
    
#define  DEBUG_USART_TX_GPIO_PORT_SYN6288        GPIOB   
#define  DEBUG_USART_TX_GPIO_PIN_SYN6288         GPIO_Pin_10
#define  DEBUG_USART_RX_GPIO_PORT_SYN6288        GPIOB
#define  DEBUG_USART_RX_GPIO_PIN_SYN6288         GPIO_Pin_11

#define  DEBUG_USART_IRQ_SYN6288                 USART3_IRQn
#define  DEBUG_USART_IRQHandler_SYN6288          USART3_IRQHandler



void SYN6288_GPIO_Config ( void );
void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch);
void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str );
void SYN688_USART_Config(void);
void Usart_SYN6288_SendByte( USART_TypeDef * pUSARTx, uint8_t ch);
void SYN_FrameInfo(char *HZdata);
void Usart_SSYN6288_endString( USART_TypeDef * pUSARTx, char *str);
/* 音量控制 */
void Volinme(uint8_t Y_L);
/* 语调控制 */
void Intonation(uint8_t Y_L);
/* 语速控制 */
void Speed_pacing(uint8_t Y_L);
/* 人控制 */
void speed_man(uint8_t Y_L);
#endif /*_SYN6288_H_*/
/* End of File ------------------------------------------------------------- */



syn8266.c

/**
******************************************************************************
*  @File     SYN6288.c
*  @Author   Velscode  
*  @Email    velscode@gmail.com
*  @Brief    TTS 芯片 SYN6288驱动源代码文件(基于STM32F10x)
*            使用了USART2(A2\A3)
******************************************************************************
*/

/* Internal Function Declaration ------------------------------------------- */
void usart2_Init(unsigned int bound);

/* Header Files ------------------------------------------------------------ */
#include "SYN6288.h"
#include "string.h"
/* RT-Thread相关头文件 */
#include <rthw.h>
#include <rtthread.h>
#include <string.h>
struct  STRUCT_USARTx_Fram strUSART_Fram_Record = { 0 };

 /**
  * @brief  配置嵌套向量中断控制器NVIC
  * @param  无
  * @retval 无
  */
static void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* 嵌套向量中断控制器组选择 */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  
  /* 配置USART为中断源 */
  NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_IRQ_SYN6288;
  /* 抢断优先级*/
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  /* 子优先级 */
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  /* 使能中断 */
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  /* 初始化配置NVIC */
  NVIC_Init(&NVIC_InitStructure);
}
//读忙
void SYN6288_GPIO_Config ( void )
{		
	/*定义一个GPIO_InitTypeDef类型的结构体*/
	GPIO_InitTypeDef GPIO_InitStructure;


	/* 配置 LED1 引脚 */
	SYN6288_GPIO_APBxClock_FUN(SYN6288_GPIO_CLK, ENABLE); 															   
	GPIO_InitStructure.GPIO_Pin = SYN6288_GPIO_PIN;	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
	GPIO_Init ( SYN6288_GPIO_PORT, & GPIO_InitStructure );	
	
}

 /**
  * @brief  USART GPIO 配置,工作参数配置
  * @param  无
  * @retval 无
  */
void SYN688_USART_Config(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;

	// 打开串口GPIO的时钟
	DEBUG_USART_GPIO_APBxClkCmd(DEBUG_USART_GPIO_CLK_SYN6288, ENABLE);
	
	// 打开串口外设的时钟
	DEBUG_USART_APBxClkCmd_SYN6288(DEBUG_USART_CLK_SYN6288, ENABLE);

	// 将USART Tx的GPIO配置为推挽复用模式
	GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_GPIO_PIN_SYN6288;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(DEBUG_USART_TX_GPIO_PORT_SYN6288, &GPIO_InitStructure);

  // 将USART Rx的GPIO配置为浮空输入模式
	GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_GPIO_PIN_SYN6288;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(DEBUG_USART_RX_GPIO_PORT_SYN6288, &GPIO_InitStructure);
	
	// 配置串口的工作参数
	// 配置波特率
	USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
	// 配置 针数据字长
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	// 配置停止位
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	// 配置校验位
	USART_InitStructure.USART_Parity = USART_Parity_No ;
	// 配置硬件流控制
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	// 配置工作模式,收发一起
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	// 完成串口的初始化配置
	USART_Init(DEBUG_USART_SYN6288, &USART_InitStructure);
	
	// 串口中断优先级配置
	NVIC_Configuration();
	
	// 使能串口接收中断
	USART_ITConfig(DEBUG_USART_SYN6288, USART_IT_RXNE, ENABLE);	
	
	// 使能串口
	USART_Cmd(DEBUG_USART_SYN6288, ENABLE);		

  // 清除发送完成标志
	//USART_ClearFlag(USART1, USART_FLAG_TC);     
}
//其实是USART2_Send_Byte
/*****************  发送一个字符 **********************/
void Usart_SYN6288_SendByte( USART_TypeDef * pUSARTx, uint8_t ch)
{
	/* 发送一个字节数据到USART */
	USART_SendData(pUSARTx,ch);
		
	/* 等待发送数据寄存器为空 */
	while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);	
}
/*****************  发送字符串 **********************/
void Usart_SSYN6288_endString( USART_TypeDef * pUSARTx, char *str)
{
	unsigned int k=0;
  do 
  {
      Usart_SYN6288_SendByte( pUSARTx, *(str + k) );
      k++;
  } while(*(str + k)!='\0');
  
  /* 等待发送完成 */
  while(USART_GetFlagStatus(pUSARTx,USART_FLAG_TC)==RESET)
  {}
}

//语音合成
void SYN6288_Speech( USART_TypeDef * pUSARTx,char * str )
{
	
	if(SYN6288_Read_GPIO_IN()==Bit_RESET)/* x us后仍为高电平表示数据“1” */
	{

				char * p = str;
		int len = 0,check=0xFD,i;
		
		while( *p++ != 0 )
		{
				len++;
		
		}
		
		len+=3;
		
		Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
		
		Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,len / 256 );
		Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,len % 256 );
		check  = check ^ ( len / 256 ) ^ ( len % 256 );
		
		Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,0x01 );
		Usart_SYN6288_SendByte( DEBUG_USART_SYN6288,0x01 );
		check = check ^ 0x01 ^ 0x01;
		
		for( i = 0; i < len-3; i++ )
		{
				Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,*str);
				check ^= ( *str );
				str++;
		}
		Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,check);   
				
		rt_thread_delay(150*len);	
	}	

}
/* 音量控制 */
void Volinme(uint8_t Y_L)
{
		uint8_t num ;
	num = Y_L+48;
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x76);
	//控制音量
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
	
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
//	uint8_t num[9] ;
//	
//	num[0] = 0xFD;
//	num[1] = 0x00;
//	num[2] = 0x06;
//	num[3] = 0x01;
//	num[4] = 0x01;
//	num[5] = 0x5B;
//	num[6] = 0x76;
//	//控制音量
//	num[7] = Y_L+48;
//	num[8] = 0x5D;
//	
//	Usart_SendByte(DEBUG_USARTx,num[8]);
}
/* 语调控制 */
void Intonation(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x74);
	//控制音量
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
	
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
	

}
/* 语速控制 */
void Speed_pacing(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x06);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x73);
	//控制音量
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
	
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
	
}
/* 人控制 */
void speed_man(uint8_t Y_L)
{
	uint8_t num ;
	num = Y_L+48;
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0xFD);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x00);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x07);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x01);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5B);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x6D);
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x35);
	//控制音量
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,num);
	
	Usart_SYN6288_SendByte(DEBUG_USART_SYN6288,0x5D);
	
}
/* End of File ------------------------------------------------------------- */



stm32f10x_it.t添加中断函数

/* 该文件统一用于存放中断服务函数 */
#include "stm32f10x_it.h"
#include "SYN6288.h"
// 串口中断服务函数
void DEBUG_USART_IRQHandler_SYN6288(void)
{
  uint8_t ucCh;
	if ( USART_GetITStatus ( DEBUG_USART_SYN6288, USART_IT_RXNE ) != RESET )
	{
		ucCh  = USART_ReceiveData( DEBUG_USART_SYN6288 );
		
		if ( strUSART_Fram_Record .InfBit .FramLength < ( RX_BUF_MAX_LEN - 1 ) )                       //预留1个字节写结束符
			   strUSART_Fram_Record .Data_RX_BUF [ strUSART_Fram_Record .InfBit .FramLength ++ ]  = ucCh;

	}
	 	 
	if ( USART_GetITStatus( DEBUG_USART_SYN6288, USART_IT_IDLE ) == SET )                                         //数据帧接收完毕
	{
    strUSART_Fram_Record .InfBit .FramFinishFlag = 1;		
		
		ucCh = USART_ReceiveData( DEBUG_USART_SYN6288 );                                                              //由软件序列清除中断标志位(先读USART_SR,然后读USART_DR)	
  }	
}

初始化syn8266

//语音播报系统
	  SYN6288_GPIO_Config();
	  SYN688_USART_Config();

在主函数中使用

//APP2
static void APP2_thread_entry(void* parameter)
{		
	rt_uint8_t key=0;
	rt_uint8_t dispBuff[100];
	rt_uint8_t t=0;	
	rt_uint8_t *str=0;
	while(1)
	{

	  key=Remote_Scan();
			
		if(key)
		{	
		switch(key)
			{
				case 162:
						//1
						str= "· time 10min·";
						munite = 10;
						hour=0;		
						second=0;
				    SYN6288_Speech(DEBUG_USART_SYN6288,"定时十分钟");
				    
            break;
        
        case 98:
						//2					
					  str= "· time 20min·";
            munite = 20;
						hour=0;	
						second=0;
				    SYN6288_Speech(DEBUG_USART_SYN6288,"定时二十分钟");
            break;
        
        case 226://3
					 str= "· time 30min·";
					 munite = 30;
					hour=0;	
						second=0;
            SYN6288_Speech(DEBUG_USART_SYN6288,"定时三十分钟");
						break;
        
        case 34://4
					 str= "· time 40min·";
						munite = 40;
					  hour=0;	
				    second=0;
						SYN6288_Speech(DEBUG_USART_SYN6288,"定时四十分钟");
            break;
        
        case 2://5
					 str= "· time 50min·";
           munite = 50;
					 hour=0;
					 second=0;
					 SYN6288_Speech(DEBUG_USART_SYN6288,"定时五十分钟");
            break;
        
        case 194://6
					 str= "· time 60min·";
           munite = 60;
					hour=0;
					second=0;
					SYN6288_Speech(DEBUG_USART_SYN6288,"定时六十分钟");
            break;
        
        case 224://7
					 str= "· time 90min·";
					 hour = 1;
           munite = 30;
					 second=0;
				   SYN6288_Speech(DEBUG_USART_SYN6288,"定时一个半小时");
            break;
        
        case 168://8
					 str= "· time  2h ·";
           hour = 1;
					munite = 60;
					second=0;
					SYN6288_Speech(DEBUG_USART_SYN6288,"定时两个小时");
            break;
        
        case 144://9
					SYN6288_Speech(DEBUG_USART_SYN6288,"定时三个小时");
					 str= "· time  3h ·";
           hour = 2;
						munite = 60;
						second=0;
				   
            break;
        
        case 152:
					 str= "detected code 0";
            name();
					  
            break;
        
        case 104:
					 str= "detected code *";
           
            break;
        
        case 176:
					 str= "detected code #";
           
            break;
                
        case 24:
					 str= "detected code ↑";
          
            break;
                
        case 16:
					 str= "detected code ←";
            
            break;
        
        case 74:
					  str= "detected code ↓";
         
            break;
        
        case 90:
					  str= "detected code →";
            break;
        
        case 56:
            str= "detected code OK ";
            break;
        
        default:
					  str= "EMOURE";
         
            break;

			}
			Draw_Font16B(4,100,BRRED,str);	//显示SYMBOL
			key = 0;
//			uwRet = rt_thread_resume(APP3_thread);/* 恢复APP3线程! */
//			if(RT_EOK == uwRet)
//			{
//				rt_kprintf("恢复APP3线程成功!\n");
//			}
//			else
//			{
//				rt_kprintf("恢复APP3线程失败!失败代码:0x%lx\n",uwRet);
//			}
			
		}
		
	}

}

附上代码连接 红外+语音播报 

版权声明:本文为CSDN博主「HR_CMD」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/herui_2/article/details/121663379

生成海报
点赞 0

HR_CMD

我还没有学会写个人说明!

暂无评论

发表评论

相关推荐

基于STM32F103的智能门锁系统

基于STM32F103的智能门锁系统 直接说明实现了什么效果 1 指纹解锁(基于AS608) 2 RFID解锁(基于RC522) 3 密码解锁 (基于LCD电容屏触摸控制) 4 蓝牙解锁

ESP8266与PCA9685通信I2C

ESP8266与PCA9685通信I2C Talk is cheap, show you code! /*** ESP8266与PCA9685通过I2C协议通信* 功能:控制PCA9685上的16个舵机旋转0-18