说明

基于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. Python距离放弃拉近的day03

    新的一天,依旧是内容补充,补充了数学没有的运算符,in和not in,就是判断in前面的东西是不是在后面的数据中,然后新课讲了平常最常用的字符串的方法,引号的里面全部都是字符串,在其中就会又如何判断这 ...

  2. xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH ​

    xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH ...

  3. day 14 递归、匿名函数、内置函数

    三目运算符 # 三目(元)运算符:就是 if...else...语法糖# 前提:简化if...else...结构,且两个分支有且只有一条语句# 注:三元运算符的结果不一定要与条件直接性关系​cmd = ...

  4. 5-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(配置保存数据的数据库)

    配置信息如下:这是我的python软件和APP软件默认连接的配置 数据库名称:iot        编码utf8 表格名字:historicaldata 字段 id      自增,主键 date   ...

  5. string find()函数

    链接 [https://www.cnblogs.com/wkfvawl/p/9429128.html]

  6. 为什么重写了equals() 就要重写hashcode()

    规定:1.两个对象相等,则hashcode也一定是相等的:2.两个对象相等,对两个对象分别调用equals()都返回 true:3.两个对象有相同的hashcode,但不一定相等 为什么重写了equa ...

  7. iview table行render渲染不同的组件

    table不同的行,相同的列渲染不同的组件,如图1:第一行渲染selece,第二行渲染input render:(h,params)=>{ if(params.index === 0){ //以 ...

  8. Zookeeper连接eclipse

    package com.bw.ZK; import java.io.IOException; import org.apache.zookeeper.CreateMode; import org.ap ...

  9. Java Mail 实现第三方邮件发送功能

    1 创建一个用于发送邮件的类 package com.latiny.service; import java.io.IOException; import java.io.InputStream; i ...

  10. java进阶学习的一些思路

    搞 Java 的年薪 40W 是什么水平? - 乔戈里的回答 - 知乎 https://www.zhihu.com/question/31437847/answer/566852748 在知乎上看了他 ...