基于STM32F1的语音合成芯片SYN6288驱动

目录

  • 说明
  • SYN6288.h
  • SYN6288.c

说明

基于USART2制作,封装了各种通信协议

SYN6288.h

#ifndef _SYN6288_H_
#define _SYN6288_H_
#include "sys.h"
#include "vTime.h"
/**  *******************************************************************************  @File     SYN6288.h*  @Author   Velscode  *  @Email    velscode@gmail.com*  @Brief    TTS 芯片 SYN6288驱动头文件(基于STM32F10x)*            使用了USART2(A2\A3)*******************************************************************************/void SYN6288_Init(unsigned int bound);    void SYN6288_Send_Byte( unsigned char byte );void SYN6288_Speech( char * str );void SYN6288_Speech_Time( struct vTime nt );void SYN6288_Set_Volume( int volume );void SYN6288_Play_Sound( int id );void SYN6288_Play_Msg( int id );void SYN6288_Play_Ring( int id );#endif /*_SYN6288_H_*/
/* End of File ------------------------------------------------------------- */

SYN6288.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"#include "delay.h"void SYN6288_Play_Ring( int id ){char str[6] = "ringx";if( id >= 25 )id = 25;if( id <= 0 )id = 0;str[4] = 'a'+ id;SYN6288_Speech(str);delay_ms(16);}   //播放和弦提示音void SYN6288_Play_Msg( int id ){char str[5] = "msgx";if( id >= 8 )id = 8;if( id <= 0 )id = 0;str[3] = 'a'+ id;SYN6288_Speech(str);delay_ms(16);}//播放提示音void SYN6288_Play_Sound( int id ){char str[7] = "soundx";if( id >= 25 )id = 25;if( id <= 0 )id = 0;str[5] = 'a'+ id;SYN6288_Speech(str);}//音量控制,16级可调void SYN6288_Set_Volume( int volume ){char str[6]="[vxx]";if( volume >= 16 )volume = 16;if( volume <= 0 )volume = 0;str[2] = volume/10 +'0';str[3] = volume%10 +'0';SYN6288_Speech(str);delay_ms(16);}//播报时间已完成对整点的转换支持void SYN6288_Speech_Time( struct vTime nt ){   //                          12  16  20  24  28  32   40char str[50] = "现在时间是20xx年xx月xx日xx时xx分xx秒星期x";str[12] = (nt.year/10)+'0';str[13] = (nt.year%10)+'0';str[16] = (nt.month/10)+'0';str[17] = (nt.month%10)+'0';str[20] = (nt.day/10)+'0';str[21] = (nt.day%10)+'0';str[24] = (nt.hour/10)+'0';str[25] = (nt.hour%10)+'0';if( nt.minute == 0 && nt.second == 0 ){str[28] = 0;strcat( str, "整" );}else{str[28] = (nt.minute/10)+'0';str[29] = (nt.minute%10)+'0';str[32] = (nt.second/10)+'0';str[33] = (nt.second%10)+'0';str[40] = (nt.week)+'0';}SYN6288_Speech(str);delay_ms(16);}//语音合成void SYN6288_Speech( char * str ){char * p = str;int len = 0,check=0xFD,i;while( *p++ != 0 ){len++;}len+=3;SYN6288_Send_Byte(0xFD);SYN6288_Send_Byte( len / 256 );SYN6288_Send_Byte( len % 256 );check  = check ^ ( len / 256 ) ^ ( len % 256 );SYN6288_Send_Byte( 0x01 );SYN6288_Send_Byte( 0x01 );check = check ^ 0x01 ^ 0x01;for( i = 0; i < len-3; i++ ){SYN6288_Send_Byte(*str);check ^= ( *str );str++;}SYN6288_Send_Byte(check);   delay_ms(16);}//其实是初始化USART2void SYN6288_Init(unsigned int bound){NVIC_InitTypeDef NVIC_InitStructure;GPIO_InitTypeDef GPIO_InitStructure;USART_InitTypeDef USART_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);   // GPIOA时钟RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); //串口2时钟使能USART_DeInit(USART2);  //复位串口2//USART2_TX   PA2GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA2GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA2//USART2_RX   PA3GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入GPIO_Init(GPIOB, &GPIO_InitStructure);  //初始化PA3USART_InitStructure.USART_BaudRate = bound;//波特率设置USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式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(USART2, &USART_InitStructure); //初始化串口2USART_Cmd(USART2, ENABLE);                    //使能串口 //使能接收中断USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启中断   //设置中断优先级NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级3NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;      //子优先级3NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;         //IRQ通道使能NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器}//其实是USART2_Send_Bytevoid SYN6288_Send_Byte( unsigned char byte ){while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET);USART_SendData(USART2,byte); }/* End of File ------------------------------------------------------------- */

转载于:https://www.cnblogs.com/velscode/p/10105505.html


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部