|
STC12C5A60S2系列單片機, 帶內(nèi)建的UART2, 可以雙串口輸出, 基于 HML_FwLib_STC12 封裝庫可以方便的初始化并調(diào)用第二串口, 使用第二串口的代碼
- #include "hml/hml.h"
- void sys_init(void)
- {
- UART2_configTypeDef uc;
- uc.baudrate = 115200; /* baud rate is 115200bps */
- uc.brtPrescaler = RCC_BRT_prescaler_1; /* 1T mode */
- uc.interruptState = ENABLE;
- uc.interruptPriority = DISABLE;
- uc.mode = UART_mode_1;
- uc.doubleBaudrate = DISABLE;
- uc.receiveState = ENABLE;
- uc.pinmap = UART2_pinmap_P1;
- UART2_config(&uc);
- }
- void main(void)
- {
- sys_init();
- while (true)
- {
- /* send per 500ms */
- sleep(500);
- UART2_sendString("Hello, world!\r\n");
- }
- }
復(fù)制代碼
注意: 第二串口UART2只能使用獨立的BRT作為波特率發(fā)生器, 而UART1可以切換選擇BRT和TIM1. 因為STC12有1T模式, 因此可以在11.0529MHz晶振下很輕松的實現(xiàn)115200波特率. 在啟用 1T + 雙倍的模式下, 可以實現(xiàn)345600的波特率
- #include "hml/hml.h"
- void sys_init(void)
- {
- UART2_configTypeDef uc;
- uc.baudrate = 345600; /* baud rate is 345600 */
- uc.brtPrescaler = RCC_BRT_prescaler_1; /* 1T mode */
- uc.interruptState = ENABLE;
- uc.interruptPriority = DISABLE;
- uc.mode = UART_mode_1;
- uc.doubleBaudrate = ENABLE;
- uc.receiveState = ENABLE;
- uc.pinmap = UART2_pinmap_P1;
- UART2_config(&uc);
- }
- void main(void)
- {
- sys_init();
- while (true)
- {
- /* send per 500ms */
- sleep(500);
- UART2_sendString("Hello, world!\r\n");
- }
- }
復(fù)制代碼
|
評分
-
查看全部評分
|