说明

基于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 40
char 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);
} //其实是初始化USART2
void 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 PA2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA2 //USART2_RX PA3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化PA3 USART_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); //初始化串口2 USART_Cmd(USART2, ENABLE); //使能串口 //使能接收中断
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启中断 //设置中断优先级
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
} //其实是USART2_Send_Byte
void SYN6288_Send_Byte( unsigned char byte )
{
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET);
USART_SendData(USART2,byte);
} /* End of File ------------------------------------------------------------- */

基于STM32F1的语音合成芯片SYN6288驱动的更多相关文章

  1. 基于STM32F1的时钟芯片DS1302驱动

    目录 DS1302.h源代码 DS1302.c源代码 DS1302.h源代码 /** ********************************************************* ...

  2. 基于STM32F1的局域网通信模块W5500驱动

    目录 说明 W5500 W5500.c 使用方法 说明 需要调整的内容为W5500.h中关于IP地址.端口号.子网掩码.网关等参数 W5500 #ifndef _W5500_H_ #define _W ...

  3. uboot的GPIO驱动分析--基于全志的A10芯片【转】

    本文转载自:http://blog.csdn.net/lw2011cg/article/details/68954707 uboot的GPIO驱动分析--基于全志的A10芯片 转载至:http://b ...

  4. 基于STM32F1与NRF24L01模块的SPI简单通信

    一.前言 1.简介: 本文是基于STM32F1,将数据发送至NRF模块的寄存器,并将数据重新读取,通过串口发送出来的简单SPI单通信. 2.SPI简介: 调过STM8的都已经对SPI有所了解,调法都一 ...

  5. LCD显示--Ht1621b芯片显示屏驱动

    Ht1621b芯片显示屏驱动 关于HT1621b芯片的具体信息能够參考数据手冊上的内容:百度文库HT1621b中文资料 CS : 片选输入接一上拉电阻当/CS 为高电平读写HT1621的数据和命令无效 ...

  6. 东芝线阵CCD芯片TCD1305DG驱动时序设计

    最近在做微型光谱仪,用到了东芝的CCD芯片TCD1305DG,该芯片是单行3648像素,输出信号是时间上离散的模拟信号,典型输出速率为0.5M,即每2000ns输出一个像素值(模拟信号),芯片内部集成 ...

  7. 基于STM32F1 的BASIC解码实验 vb basic 液晶显示执行过程及结果

    基于STM32F1 的BASIC解码实验 1.basic程序以文件形式存储 2.程序文件存储在sd卡 3.解释结果显示在液晶屏上 主函数部分 int main(void){ u16 i,j; dela ...

  8. 基于设备树的TQ2440触摸屏驱动移植

    平台 开发板:tq2440 内核:Linux-4.9 u-boot:u-boot-2015.04   概述 之前移植了LCD驱动,下面继续移植触摸屏驱动,然后将tslib也移植上去. 正文 一.移植触 ...

  9. 基于Minifilter框架的文件过滤驱动理解

    概述 Minifilter即File System Minifilter Drivers,是Windows为了简化第三方开发人员开发文件过滤驱动而提供的一套框架,这个框架依赖于一个称之为Filter ...

随机推荐

  1. MySQL数据库事务及其特性

    一.事务概念 事务就是一个程序执行单元,里面的操作要么都做,要么都不做. 二.事务特性 事务有四个非常重要的特性(ACID): 原子性(Atomicity):事务是不可分割的整体,所有操作要么全做,要 ...

  2. 爬虫基础(四)-----MongoDB的使用

    ------------------------------------------------------------------------摆脱穷人思维 <四> :减少无意义的频繁决策 ...

  3. SQL 无法连接服务器

    错误信息:provider:SQL Network Interfaces, error:52-无法定位 LOCA Database Runtime 安装.请验证SQL Server Express是否 ...

  4. webpack4

    本地安装: npm init -y cnpm install webpack webpack-cli webpack-dev-server --save-dev 然后装一些所需要的loader和插件: ...

  5. Solving the Top ERP and CRM Metadata Challenges with erwin & Silwood

    Registrationhttps://register.gotowebinar.com/register/3486582555108619010 Solving the Top ERP and CR ...

  6. EQueue

    EQueue 2.3.2版本发布(支持高可用) - dotNET跨平台 - CSDN博客https://blog.csdn.net/sD7O95O/article/details/78097193 E ...

  7. mysql 5.7 json

    项目中使用的mysql5.6数据库,数据库表一张表中存的字段为blob类型的json串数据.性能压测中涉及该json串处理效率比较低,开发人员提到mysql5.7版本后json串提供了原生态的json ...

  8. Linux(Ubuntu)使用日记(三)------git安装使用

    1. 安装 首先,确认你的系统是否已安装git,可以通过git指令进行查看,如果没有,在命令行模式下输入sudo apt-get install git命令进行安装. 2.  配置 git confi ...

  9. JarvisOJ Basic 握手包

    得到的是一个.cap文件,我看着好像可以用wireshark打开,就试了一下 报错了,pcapfix上,得到了一个新的.cap文件,用wireshark打开,发现分析不出来 查了一下,有破解握手包的专 ...

  10. 通过SQL脚本来查询SQLServer 中主外键关系

    在SQLServer中主外键是什么,以及主外键如何创建,在这里就不说了,不懂的可以点击这里,这篇文章也是博客园的博友写的,我觉得总结的很好: 此篇文章主要介绍通过SQL脚本来查看Sqlserver中主 ...