基于STM32F1的语音合成芯片SYN6288驱动
说明
基于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驱动的更多相关文章
- 基于STM32F1的时钟芯片DS1302驱动
目录 DS1302.h源代码 DS1302.c源代码 DS1302.h源代码 /** ********************************************************* ...
- 基于STM32F1的局域网通信模块W5500驱动
目录 说明 W5500 W5500.c 使用方法 说明 需要调整的内容为W5500.h中关于IP地址.端口号.子网掩码.网关等参数 W5500 #ifndef _W5500_H_ #define _W ...
- uboot的GPIO驱动分析--基于全志的A10芯片【转】
本文转载自:http://blog.csdn.net/lw2011cg/article/details/68954707 uboot的GPIO驱动分析--基于全志的A10芯片 转载至:http://b ...
- 基于STM32F1与NRF24L01模块的SPI简单通信
一.前言 1.简介: 本文是基于STM32F1,将数据发送至NRF模块的寄存器,并将数据重新读取,通过串口发送出来的简单SPI单通信. 2.SPI简介: 调过STM8的都已经对SPI有所了解,调法都一 ...
- LCD显示--Ht1621b芯片显示屏驱动
Ht1621b芯片显示屏驱动 关于HT1621b芯片的具体信息能够參考数据手冊上的内容:百度文库HT1621b中文资料 CS : 片选输入接一上拉电阻当/CS 为高电平读写HT1621的数据和命令无效 ...
- 东芝线阵CCD芯片TCD1305DG驱动时序设计
最近在做微型光谱仪,用到了东芝的CCD芯片TCD1305DG,该芯片是单行3648像素,输出信号是时间上离散的模拟信号,典型输出速率为0.5M,即每2000ns输出一个像素值(模拟信号),芯片内部集成 ...
- 基于STM32F1 的BASIC解码实验 vb basic 液晶显示执行过程及结果
基于STM32F1 的BASIC解码实验 1.basic程序以文件形式存储 2.程序文件存储在sd卡 3.解释结果显示在液晶屏上 主函数部分 int main(void){ u16 i,j; dela ...
- 基于设备树的TQ2440触摸屏驱动移植
平台 开发板:tq2440 内核:Linux-4.9 u-boot:u-boot-2015.04 概述 之前移植了LCD驱动,下面继续移植触摸屏驱动,然后将tslib也移植上去. 正文 一.移植触 ...
- 基于Minifilter框架的文件过滤驱动理解
概述 Minifilter即File System Minifilter Drivers,是Windows为了简化第三方开发人员开发文件过滤驱动而提供的一套框架,这个框架依赖于一个称之为Filter ...
随机推荐
- linux 下 命令行中运行 selenium chrome 问题
1.chrome 现在不允许使用root运行了. 2.无界面 chromedriver 调用chrome 会出错. <另外一定要匹配 chromedriver和chrome 的版本. 要不会出各 ...
- java获取类加载路径和项目根路径的5种方法
// 第一种:获取类加载的根路径 D:\IDEAWorkspace\hs-bluetooth-lock\src\applications\bluetooth-api\target\classes Fi ...
- Linux:Day13(下) GRUB
GRUB(Boot Loader): grub:GRand Unified Bootloader grub 0.x:grub legacy grub 1.x:grub2 grub legacy: st ...
- Web前端知识点记录
一.HTML的加载顺序 浏览器边下载HTML,边解析HTML代码,二者是从上往下同步进行的 先解析<head>中的代码,在<head>中遇到了<script>标签, ...
- cnblogs 支持 iframe 标签 !
bilibili 视频嵌入支持 网易云音乐支持 关注窝(求求你 ฅฅ) 这是我制作的第一个鬼畜(好傻的,视频直接录制的,进度条都录制上了,不过没关系的,反正以后也不做了(* /ω\*)) 说明 原来是 ...
- iOS开发基础-图片切换(2)之懒加载
延续:iOS开发基础-图片切换(1),对(1)里面的代码进行改善. 在 ViewController 类中添加新的数组属性: @property (nonatomic, strong) NSArra ...
- rxjs一句话描述一个操作符(1)
之前一直在写LINQ之类的东西,对于函数式的面向对象还是有一些功底,所以对于rxjs,感觉上不是很难,但是每次看完过几天就忘,还是记一下笔记吧,好记性不如烂笔头真不是盖的. 首先介绍几个重要的概念. ...
- SELECT list is not in GROUP BY clause and contains nonaggregated column
报错如下: Expression # of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘sss.m ...
- Python开发第一篇
Python 是什么? 首先他可能是比较好的一个编程开发语言!
- 解决 MariaDB无密码就可以登录的问题
问题: 困扰了很久的问题,, 使用apt-get来安装mysql,安装好之后发现安装的是 MariaDB,如下,无需密码既可以登录了.即使使用mysqladmin设置好密码,用密码登录可以,不用密码登 ...