- /*
- STM32F103VCT6与SYN6288硬件接口非常简单,采用串口通讯方式,
- PA9(USART/TX)-->SYN6288_RX(芯片RX引脚需要外接个电平转换,我画的测试板上已经有转换电路了)
- PA10(USART/RX)<--SYN6288_TX
- PE2(PIN1),<---> SYN6288_BUSY (可不接)
- 调用示例:
- TTSPlay('m',"欢迎光临xxxx休闲娱乐中心");
- */
- 函数代码:
- /***********************************************
- 声音播放代码,实现自动计算校验值
- 第一参数:提示音乐音类型,具体参考官方示例程序
- 第二参数:播放的文本内容
- (SoundVol是个音量值的全局变量)
- ************************************************/
- void TTSPlay(u8 sound,char *Text)
- {
- va_list arg_ptr;
- u8 i=0,xorcrc=0,uLen;
- u8 SoundBuf[110]; //操作语音提示缓冲
- char tmpBuf[120]; //
- uLen = (u8)vsprintf(tmpBuf, Text, arg_ptr);
- for (i=0;i<100;i++) SoundBuf=0x00;
- SoundBuf[0]=0xFD;
- SoundBuf[1]=0x00;
- SoundBuf[2]=uLen+15;
- SoundBuf[3]=0x01;
- SoundBuf[4]=0x01;
- SoundBuf[5]='[';
- SoundBuf[6]='v';
- SoundBuf[7]=ASCIICODE[SoundVol/10];
- SoundBuf[8]=ASCIICODE[SoundVol%10];
- SoundBuf[9]=']';
- SoundBuf[10]=0x73;
- SoundBuf[11]=0x6F;
- SoundBuf[12]=0x75;
- SoundBuf[13]=0x6E;
- SoundBuf[14]=0x64;
- SoundBuf[15]=sound; //有效值a-v,函数的第一个参数,声音提示之前的音乐声
- SoundBuf[16]=0x2C;
- for (i=0;i<uLen;i++)
- {
- SoundBuf[17+i]=tmpBuf;
- }
- for (i=0;i<uLen+17;i++)
- {
- xorcrc=xorcrc ^ SoundBuf;
- USART_Send_Byte(SoundBuf);
- }
- USART_Send_Byte(xorcrc);
- }
- /***************************
- 串口配置函数
- ***************************/
- void USART_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- USART_InitStructure.USART_BaudRate = 9600;
- 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(USART1, &USART_InitStructure);
- USART_Cmd(USART1, ENABLE);
- USART_ClearFlag(USART1, USART_FLAG_TC);
- }
- /***************************************************************************
- 参数说明:mydata待发送的数据
- 返回说明:无
- ***************************************************************************/
- void USART_Send_Byte(u8 mydata)
- {
- USART_ClearFlag(USART1,USART_FLAG_TC);
- USART_SendData(USART1, mydata);
- while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
- USART_ClearFlag(USART1,USART_FLAG_TC);
- }
复制代码 |