/****************************************************************************************************** IC : TM52F1386 演示效果 : 通过USB将开发板与电脑,打开电脑中的串口助手,设置对应端口, 9600波特率,8位数据位,无校验位,1位停止位。向学习板发送任 意1个字节数据,学习板会回传1个相同字节数据。 注意: 需要将底板的OP4端子的TX与RX跳线帽接好 时钟 : 快时钟系统主频为 18.432M/2 = 9.216M 分给定时器的时钟频率为9.216M/2 = 4.608M *********************************************************************************************************/ #include #include "TM52F1386_bsp.h" #include #include "uart2.h" //波特率= Fsys/32/UART2BRP #define SMOD_PRICE 1 #define FRC_HZ 18432000 #define FRC_DIV 2 #define BAUD4800 4800 #define BAUD9600 9600 #define BAUD19200 19200 #define BAUD38400 38400 #define BAUD57600 57600 #define BAUD115200 115200 //必须在系统一分频下 #define UART2BRP (unsigned int)(FRC_HZ/FRC_DIV/32/BAUD9600) //计算不同波特率下的UART2BRP unsigned char txrx_buf[8] = "666\r\n"; /********************************************************************************************************** **函数名称 :uart1_gpio_init **函数描述 :串口IO初始化 **输 入 :None **输 出 :None **********************************************************************************************************/ void uart2_gpio_init() { PORTIDX = PORT1; PINMOD10 = PINMOD10&0x00 | PIN_L_MODE_OD_IPU | PIN_H_MODE_PP; P1_1 = 1; // tx P1_0 = 1; // rx // p55,54 SET_REG(PORTIDX, 5); SET_REG_BITS(PINMOD54, PINMOD5, PIN_MODE_PP); // 配置为CMOS推挽输出 P5_5 = 0; SET_REG(PORTIDX, 5); SET_REG_BITS(PINMOD54, PINMOD4, PIN_MODE_PP); // 配置为CMOS推挽输出 P5_5 = 0; } /****************************************************************************************** ** 函数名称: uart2_init ** 函数描述: uart初始化函数 9600-8-1 无校验(轮询接收) ** 输入参数: 无 ** 输出参数: 无 *******************************************************************************************/ void uart2_init (void) { uart2_gpio_init(); UART2_8Bits; SCON2 = (SCON2&~SCON2_REN2_MASK) | 1 <