// Note: 51 Single-Chip Microcomputer uses a 12 m crystal oscillator serial port to send data will have errors and cannot work
// Therefore, only the 11.0592m crystal oscillator can be used.
Main. c
# Include <reg52.h>
# Include <string. h>
# Include "UART. H"
Void syn6288 (char * Tex, unsigned char Changdu );
/*************************************** *************************************
* Function count: void main (void)
* Power: Main Function
* Parameter quantity: None
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void main (void)
{
/**************** Text to be sent ******************* ***************/
Char code text [] = {"[V10] [M10] 100 metres forward "};
Char code Hubei [] = {"[V9] [M9] Hello world! "};
******************** ****************/
Uartinit ();
Syn6288 (text, sizeof (text ));
Uart_delay (200000); // latency is important
Syn6288 (Hubei, sizeof (Hubei ));
Uart_delay (100000); // latency is important
While (1 );
}
/*************************************** *************************************
* Letter count: void syn6288 (char * Tex, unsigned char Changdu)
* Function: Speech reading string
* Parameter: Tex -------- string address
* Changdu ---- long read of the string Tex
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void syn6288 (char * Tex, unsigned char Changdu)
{
Unsigned char headofframe [5];
Unsigned char length;
Unsigned char ECC = 0; // defines the validation byte
Unsigned int I = 0;
Length = Changdu; // the length of the text to be sent
******************** ******************/
Headofframe [0] = 0xfd; // construct the frame header FD
Headofframe [1] = 0x00; // construct the high byte of the data area Length
Headofframe [2] = Length + 3; // construct a low byte of the data area Length
Headofframe [3] = 0x01; // construction command word: Merge Playback command
******************* *******************/
Headofframe [4] = 0x21; // construct the command parameter: the encoding format is GBK.
/**************** Without background music ****************** ********************/
// Headofframe [4] = 0x01; // constructor parameter: the encoding format is GBK.
For (I = 0; I <5; I ++) // sends the constructed five frame header bytes in sequence
{
ECC = ECC ^ (headofframe [I]); // checks whether bytes are sent.
Sbuf = headofframe [I];
While (Ti = 0) {;}// the location of the pending sending interruption flag
Ti = 0; // the flag for sending interruption is cleared.
}
For (I = 0; I <length; I ++) // sends the text data to be merged in sequence
{
ECC = ECC ^ (Tex [I]); // verifies the difference or difference of the sent bytes.
Sbuf = Tex [I];
While (Ti = 0 ){;}
Ti = 0;
// Uart_delay (10 );
}
// Uart_delay (1000 );
Sbuf = ECC; // finally sends the validation byte
While (Ti = 0 );
Ti = 0;
}
UART. c
# Include <reg52.h>
# Include <stdio. h>
# Include <string. h>
# Include "UART. H"
/*************************************** *************************************
* Letter count: void uartinit (void)
* Function: initialization of serial port interruption
* Parameter quantity: None
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void uartinit (void) // Timer mode 2
{
Pcon | = 0x80;
Scon = 0x50; // Ren = 1 allows serial acceptance. The serial port mode is 1.
Tmod | = 0x20;
// Th1 = 0xfd; // baud * 2/* reload value 19200, data bit 8, and stop bit 1. No verification site (11.0592)
Th1 = 0xfa; // baud * 2/* the baud rate is 4800, the data bit is 8, and the stop bit is 1. No verification space (110.592 m)
TL1 = 0xfa;
Tr1 = 1;
Ri = 0;
Ti = 0;
Es = 1; // enable serial port interruption
Ea = 1; // total disconnection
}
/*************************************** *************************************
* Letter count: void usart_send_byte (unsigned char data)
* Function: Send a string through the serial port.
* Parameter: Data-sent bytes
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void usart_send_byte (unsigned char data)
{
Sbuf = data;
While (! Ti );
Ti = 0;
}
/*************************************** *************************************
* Letter count: void usart_send_enter (void)
* Function: Send a string through a serial port.
* Send 0d 0a via serial port, that is, line feed by carriage return
* Note: This function is used to send 0d 0a bytes. On the "Super Terminal", there will be a carriage return line break effect.
* Parameter: Data-sent bytes
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void usart_send_enter (void)
{
Usart_send_byte (0x0d );
Usart_send_byte (0x0a );
}
/*************************************** *************************************
* Function: void usart_send_str (char * Data)
* Function: Send a string through a serial port.
* Parameter: Data-sent string pointer
* S: pointer to a string
* Note: If '\ n' is contained in the string, a carriage return line break is sent.
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void usart_send_str (char * Data)
{
Unsigned char I;
Unsigned char Len = strlen (data)-1;
For (I = 0; I <Len; I ++)
{
Usart_send_byte (data [I]);
}
If (data [I] = '\ n ')
{
Usart_send_enter ();
}
Else
{
Usart_send_byte (data [I]);
}
}
/*************************************** *************************************
* Function: void numtostr (unsigned int dat, char * Str)
* Function: convert a 32-bit variable dat into a string, for example, convert 1234 to "1234"
* Parameter: DAT: variable of the long type with rotation
* STR: pointer to the character array, where the converted byte string
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void numtostr (unsigned int dat, char * Str)
{
Char temp [20];
Unsigned int I = 0, j = 0;
I = 0;
While (DAT)
{
Temp [I] = dat % 10 + 0x30;
I ++;
Dat/= 10;
}
J = I;
For (I = 0; I <j; I ++)
{
STR [I] = temp [j-i-1];
}
If (! I) {STR [I ++] = '0 ';}
STR [I] = 0;
}
/*************************************** *************************************
* Function count: void usart_put_num (unsigned int dat)
* Function: Serial sending Value
* The function converts the value into a corresponding string and sends it out. For example, convert 4567 to "4567"
* Parameter quantity: None
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void usart_put_num (unsigned int dat)
{
Char temp [20];
Numtostr (dat, temp );
Usart_send_str (temp );
}
/*************************************** *************************************
* Letter count: void delay (unsigned int I)
* Function: latency subroutine
* Parameter quantity: None
* Return value: None
* Update: None
* Standby Note: None
**************************************** ************************************/
Void uart_delay (unsigned int I)
{
Unsigned char J;
For (I; I> 0; I --)
For (j = 500; j> 0; j --);
}
UART. h
# Ifndef _ uart_h __
# DEFINE _ uart_h __
Void uartinit (void );
Void usart_send_byte (unsigned char data );
Void usart_send_enter (void );
Void usart_send_str (char * data );
Void numtostr (unsigned int dat, char * Str );
Void usart_put_num (unsigned int dat );
Void uart_delay (unsigned int I );
# Endif
P3.1 interface rxd
You can send a question and convert it into a voice when you receive it through the serial port.
Lq_tts6288 voice Module