/*------------------------------------------------------------------*/
/* --- STC MCU International Limited -------------------------------*/
/* --- STC 1T Series MCU RC Demo -----------------------------------*/
/* If you want to use the program or the program referenced in the */
/* article, please specify in which data and procedures from STC */
/*------------------------------------------------------------------*/
/*********************************************************/
#define MAIN_Fosc 22118400L //定义主时钟
//#define MAIN_Fosc 11059200L //定义主时钟
#include "STC15Fxxxx.H"
/************* 功能说明 **************
4串口全双工中断方式收发通讯程序。
通过PC向MCU发送数据, MCU收到后通过串口把收到的数据原样返回.
默认参数:
所有设置均为 1位起始位, 8位数据位, 1位停止位, 无校验.
每个串口可以使用不同的波特率.
串口1(P3.0 P3.1): 115200bps.
串口2(P1.0 P1.1): 57600bps.
串口3(P0.0 P0.1): 38400bps.
串口4(P0.2 P0.3): 19200bps.
******************************************/
/************* 本地常量声明 **************/
#define RX1_Length 128 /* 接收缓冲长度 */
#define RX2_Length 128 /* 接收缓冲长度 */
#define RX3_Length 128 /* 接收缓冲长度 */
#define RX4_Length 128 /* 接收缓冲长度 */
#define UART_BaudRate1 115200UL /* 波特率 */
#define UART_BaudRate2 57600UL /* 波特率 */
#define UART_BaudRate3 38400UL /* 波特率 */
#define UART_BaudRate4 19200UL /* 波特率 */
/************* 本地变量声明 **************/
u8 xdata RX1_Buffer[RX1_Length]; //接收缓冲
u8 xdata RX2_Buffer[RX2_Length]; //接收缓冲
u8 xdata RX3_Buffer[RX3_Length]; //接收缓冲
u8 xdata RX4_Buffer[RX4_Length]; //接收缓冲
u8 TX1_read,RX1_write; //读写索引(指针).
u8 TX2_read,RX2_write; //读写索引(指针).
u8 TX3_read,RX3_write; //读写索引(指针).
u8 TX4_read,RX4_write; //读写索引(指针).
bit B_TX1_Busy,B_TX2_Busy,B_TX3_Busy,B_TX4_Busy; // 发送忙标志
/************* 本地函数声明 **************/
void UART1_config(u8 brt); // 选择波特率, 2: 使用Timer2做波特率, 其它值: 使用Timer1做波特率.
void UART2_config(u8 brt); // 选择波特率, 2: 使用Timer2做波特率, 其它值: 无效.
void UART3_config(u8 brt); // 选择波特率, 2: 使用Timer2做波特率, 其它值: 使用Timer3做波特率.
void UART4_config(u8 brt); // 选择波特率, 2: 使用Timer2做波特率, 其它值: 使用Timer4做波特率.
void PrintString1(u8 *puts);
void PrintString2(u8 *puts);
void PrintString3(u8 *puts);
void PrintString4(u8 *puts);
/**********************************************/
void main(void)
{
P0n_standard(0xff); //设置为准双向口
P1n_standard(0xff); //设置为准双向口
P2n_standard(0xff); //设置为准双向口
P3n_standard(0xff); //设置为准双向口
P4n_standard(0xff); //设置为准双向口
P5n_standard(0xff); //设置为准双向口
UART1_config(1); // 选择波特率, 2: 使用Timer2做波特率, 其它值: 使用Timer1做波特率.
UART2_config(2); // 选择波特率, 2: 使用Timer2做波特率, 其它值: 无效.
UART3_config(3); // 选择波特率, 2: 使用Timer2做波特率, 其它值: 使用Timer3做波特率.
UART4_config(4); // 选择波特率, 2: 使用Timer2做波特率, 其它值: 使用Timer4做波特率.
EA = 1;
PrintString1("S