|
- #ifndef SYN6288_H_
- #define SYN6288_H_
- #define uchar unsigned char
- #define HEAD_LEN 5
- #define BKM_MAX 5
- class Syn6288
- {
- public:
- Syn6288();
- void Speech(const char * txt,uchar bkm,uchar port);
- void Speech(const char * txt,uchar bkm);
- void Speech(const char * txt);
- private:
- uchar _nPort;
- uchar _nBkm;
- };
- #endif
复制代码
- #if defined(ARDUINO) && ARDUINO >= 100
- #include <Arduino.h>
- #else
- #include <WProgram.h>
- #endif
- #include "Syn6288.h"
- Syn6288::Syn6288()
- {
- _nPort = 1;
- _nBkm = 0;
- }
- void Syn6288::Speech(const char * txt,uchar bkm,uchar port)
- {
- uchar i=0;
- uchar head[5];
- uchar x=0; //FD 00 05 01 08
- head[0]=0xfd;
- head[1]=0x00;
- head[3]=0x01;
- _nPort=port;
- _nBkm=bkm % (BKM_MAX + 1);
- head[2]=sizeof(txt) + 3;
- head[4]=_nBkm << 3;
- Serial.write(head,HEAD_LEN);
- for(i=0;i<HEAD_LEN;i++)
- {
- x=x^head[i];
- if(_nPort==1)
- Serial.write(head[i]);
- }
- for(i=0;i<head[2];i++)
- {
- x=x^txt[i];
- if(_nPort==1)
- Serial.write(txt[i]);
- }
- if(_nPort == 1)
- Serial.write(x);
- }
- void Syn6288::Speech(const char * txt,uchar bkm)
- {
- Speech(txt,bkm,_nPort);
- }
- void Syn6288::Speech(const char * txt)
- {
- Speech(txt,_nBkm,_nPort);
- }
复制代码
上面是库文件 想问一下 _nBkm 这个变量是什么? bkm 又是什么? 现在可以编译通过,但是通过端口监视器查看 输出的数据只有 前5段头代码,没有TXT 内容代码,我想这个库文件应该是无法把汉字直接转换成 GB2312编码的,于是把TXT 内容换成 GB2312代码还是无法输出txt内容,
下面是 程序代码 - #include <Syn6288.h>
- Syn6288 myTalk;
- void setup() {
- Serial.begin(9600); // set up Serial library at 9600 bps
- }
- void loop() {
- myTalk.Speech("文本1",1,2);
- delay(3000);
- }
复制代码 |
|