芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

飞芯科技-芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

IC解密STC12单片机的UART2串口输出 源程序

IC解密STC12C5A60S2系列单片机, 带内建的UART2, 可以双串口输出, 基于IC解密封装库可以方便的初始化并调用第二串口, 使用第二串口的代码


  1. #include "hml/hml.h"

  2. void sys_init(void)
  3. {
  4.     UART2_configTypeDef uc;
  5.     uc.baudrate                    = 115200;                         /* baud rate is 115200bps */
  6.     uc.brtPrescaler                = RCC_BRT_prescaler_1;            /* 1T mode */
  7.     uc.interruptState              = ENABLE;
  8.     uc.interruptPriority           = DISABLE;
  9.     uc.mode                        = UART_mode_1;
  10.     uc.doubleBaudrate              = DISABLE;
  11.     uc.receiveState                = ENABLE;
  12.     uc.pinmap                      = UART2_pinmap_P1;
  13.     UART2_config(&uc);
  14. }


  15. void main(void)
  16. {
  17.     sys_init();

  18.     while (true)
  19.     {
  20.         /* send per 500ms */
  21.         sleep(500);
  22.         UART2_sendString("Hello, world!\r\n");
  23.     }
  24. }

复制代码

注意: 第二串口UART2只能使用独立的BRT作为波特率发生器, 而UART1可以切换选择BRT和TIM1. 因为STC12有1T模式, 因此可以在11.0529MHz晶振下很轻松的实现115200波特率. 在启用 1T + 双倍的模式下, 可以实现345600的波特率

  1. #include "hml/hml.h"

  2. void sys_init(void)
  3. {
  4.     UART2_configTypeDef uc;
  5.     uc.baudrate                    = 345600;                         /* baud rate is 345600 */
  6.     uc.brtPrescaler                = RCC_BRT_prescaler_1;            /* 1T mode */
  7.     uc.interruptState              = ENABLE;
  8.     uc.interruptPriority           = DISABLE;
  9.     uc.mode                        = UART_mode_1;
  10.     uc.doubleBaudrate              = ENABLE;
  11.     uc.receiveState                = ENABLE;
  12.     uc.pinmap                      = UART2_pinmap_P1;
  13.     UART2_config(&uc);
  14. }

  15. void main(void)
  16. {
  17.     sys_init();

  18.     while (true)
  19.     {
  20.         /* send per 500ms */
  21.         sleep(500);
  22.         UART2_sendString("Hello, world!\r\n");
  23.     }
  24. }



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.feixindz.com
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信