我用官方的库函数如何配置串口先发高位还是先发低位?我尝试用寄存器配置,但是没有成功,
芯片是:STC8A8K64D4 。
我的代码是:
- ///////////////////////////////////////////////////
- /******************* IO配置函数 *******************/
- void UART4_GPIO_config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure; //结构定义
-
- GPIO_InitStructure.Pin = GPIO_Pin_2 | GPIO_Pin_3; //指定要初始化的IO, GPIO_Pin_0 ~ GPIO_Pin_7
- GPIO_InitStructure.Mode = GPIO_PullUp; //指定IO的输入或输出方式,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
- GPIO_Inilize(GPIO_P0,&GPIO_InitStructure); //初始化
- }
-
- /*************** 串口初始化函数 *****************/
- void UART4_config(void)
- {
-
-
- COMx_InitDefine COMx_InitStructure; //结构定义
- COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
- COMx_InitStructure.UART_BRT_Use = BRT_Timer4; //选择波特率发生器, BRT_Timer2, BRT_Timer4 (注意: 串口2固定使用BRT_Timer2)
- COMx_InitStructure.UART_BaudRate =16384ul;//16393ul; 115200; //波特率, 110 ~ 115200
- COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE
- UART_Configuration(UART4, &COMx_InitStructure); //初始化串口4 UART1,UART2,UART3,UART4
- NVIC_UART4_Init(ENABLE,Priority_1); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
-
- UART4_SW(UART4_SW_P02_P03); //UART4_SW_P02_P03,UART4_SW_P52_P53
- // 关键配置:设置数据发送顺序为MSB优先(高位先发)
- // PCON |= 0x80; // SMOD0=1 → MSB First
-
- // 关键配置:设置数据发送顺序为LSB优先(低位先发)
- PCON &= ~0x80; // SMOD0=0 → LSB First(默认)
- }
复制代码
|