#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;
}
*/
|