找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1495|回复: 1
打印 上一主题 下一主题
收起左侧

语音芯片驱动程序

[复制链接]
跳转到指定楼层
楼主
ID:386219 发表于 2018-12-21 14:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "sys.h"
#include "usart.h"
#include "string.h"
#include "stdio.h"
#include "SysTick.h"
#include "yuyin.h"

#define LEN_OFFSET    2  //长度字节的偏移量(本例中长度不超过255字节,因此只使用1字节长度)

//数据包头(0xFD + 2字节长度 + 1字节命令字 + 1字节命令参数)
unsigned char head[] = {0xfd,0x00,0x00,0x01,0x00};
    /****/         
u8 text1[]={"今日特价"};
u8 text2[]={"[v15]白菜九毛8一斤,长豆角两块九毛八一斤,土豆一块九毛八一斤"};
u8 text3[]={"[v15]猪肉十三块8毛一斤 胡萝卜一块九毛八一斤,芹菜一块九毛八一斤"};
void TTS_Init(void)
{

        GPIO_InitTypeDef  GPIO_InitStructure;
                                       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);      
                                       
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0;                           
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置成上拉输入
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;              
        GPIO_Init(GPIOD, &GPIO_InitStructure);         //根据设定参数初始化GPIOB.0               

}
void Speech(char *buf)
{
        unsigned char i = 0;          //循环计数变量
        unsigned char xor = 0x00;     //校验码初始化
        unsigned char len=strlen(buf);               
        head[LEN_OFFSET] = len + 3;  //计算正文长度(1命令字 + 1命令参数 + 文字长度 + 1校验位)

        //发送数据包头(0xFD + 2字节长度 + 1字节命令字 + 1字节命令参数)
        for(i = 0; i < 5; i++)
        {
                xor ^= head[i];
                uart3_send_char(head[i]);
                delay_ms(2);
           }

        //发送文字内容
        for(i = 0; i < len; i++)
        {
                xor ^= buf[i];
                uart3_send_char(buf[i]);
                delay_ms(2);
        }

uart3_send_char(xor);        //发送校验位
}
void speech_number(u16 i,u16 len)
{
        switch(i)
        {
                case 0:        Speech("0");break;
                case 1:        Speech("1");break;
                case 2:        Speech("2");break;
                case 3:        Speech("3");break;
                case 4:        Speech("4");break;
                case 5:        Speech("5");break;
                case 6:        Speech("6");break;
                case 7:        Speech("7");break;
                case 8:        Speech("8");break;
                case 9:        Speech("9");break;
                case 10:        Speech("10");break;
                case 11:        Speech("11");break;
                default:Speech("错误 没有查找到该数字 请在本函数中添加");
        }
}

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
。h
#ifndef __YUYIN_H__
#define __YUYIN_H__
#include "stm32f10x.h"

/***********************************第一个程序*********************************************/
extern u8 text1[];
extern u8 text2[];
extern u8 text3[];
extern u8 text4[];
extern u8 text5[];

#define  TTS_Busy        PDin(2)
void TTS_Init(void);
void Speech(char *buf);// 语音程序
void speech_number(u16 i,u16 len);

#endif  


/*--------------------------****main函数****----------------------------------*/


char yinliang[] = "[v1]";
char yusu[] = "[t5]";
char welcome[] = "欢迎使用";
char thanks[] = "谢谢";
char Moratorium[] = "此卡已冻结";
char lost[] = "此卡已挂失";
char insufficient_Balance[] = "余额不足";
char _shuaka[] = "请刷卡";
char __qingchu[] = "正在清除请稍后";
char __wancheng[] = "清除成功";
char lcd_error[] = "没有检测到液晶屏";
char _tishi_yin[] = "sounde";
char _add_caipin[]="添加成功";
char _button_write_error[]="输入错误";
char _button_write_ok[]="修改成功";
char _zlg522s_rx_error[]="请重刷";

int main()
{
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2^2=4max
  //usart_init();

       
//        TTS_Init();
          usart1_init();
                delay_s(1);
                yuiyn_number(10);
                send_yuyin_n(yinliang);
                while(1)
                {      
       
                        //Speech(text1[] ,3);

                        send_yuyin_n(_tishi_yin);
                                delay_s(2);
                        //send_yuyin_n(__qingchu);
                        send_yuyin_n(insufficient_Balance);
                                                delay_s(5);
                        send_yuyin_n(_button_write_error);
                }
               
return 0;
}
*/


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2018-12-21 17:12 | 只看该作者
补全头文件 工程包 原理图详细说明一下电路连接即可获得100+黑币
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表