[单片机芯片] printf输出卡顿

[复制链接]
 楼主| 寂静之回响 发表于 2025-8-4 11:41 | 显示全部楼层 |阅读模式
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name          : Main.c
  3. * Author             : WCH
  4. * Version            : V1.0
  5. * Date               : 2020/08/06
  6. * Description        : 串口1收发演示
  7. *********************************************************************************
  8. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  9. * Attention: This software (modified or not) and binary are used for
  10. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  11. *******************************************************************************/


  12. #include "CH57x_common.h"


  13. uint8_t TxBuff[] = "This is a tx exam\r\n";
  14. uint8_t RxBuff[100];
  15. uint8_t trigB;


  16. /*********************************************************************
  17. * @fn      main
  18. *
  19. * [url=home.php?mod=space&uid=247401]@brief[/url]   主函数
  20. *
  21. * [url=home.php?mod=space&uid=266161]@return[/url]  none
  22. */
  23. int main()
  24. {
  25.     uint8_t len;


  26.     SetSysClock(CLK_SOURCE_PLL_60MHz);


  27.     /* 配置串口1:先配置IO口模式,再配置串口 */
  28.     GPIOA_SetBits(GPIO_Pin_9);
  29.     GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU);      // RXD-配置上拉输入
  30.     GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
  31.     UART1_DefInit();


  32. #if 1 // 测试串口发送字符串
  33.     UART1_SendString(TxBuff, sizeof(TxBuff));


  34. #endif


  35. #if 1 // 查询方式:接收数据后发送出去



  36. PRINT("start\n");
  37.     while(1)
  38.     {
  39.         // len = UART1_RecvString(RxBuff);
  40.         // if(len)
  41.         // {
  42.         //     UART1_SendString(RxBuff, len);
  43.         // }
  44.         //UART1_SendString("1234", 4);
  45.         printf("666");
  46.         DelayMs(1000);
  47.     }


  48. #endif


  49. #if 0 // 中断方式:接收数据后发送出去
  50.     UART1_ByteTrigCfg(UART_7BYTE_TRIG);
  51.     trigB = 7;
  52.     UART1_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_LINE_STAT);
  53.     PFIC_EnableIRQ(UART1_IRQn);
  54. #endif


  55.     while(1);
  56. }


  57. /*********************************************************************
  58. * @fn      UART1_IRQHandler
  59. *
  60. * @brief   UART1中断函数
  61. *
  62. * @return  none
  63. */
  64. __attribute__((interrupt("WCH-Interrupt-fast")))
  65. __attribute__((section(".highcode")))
  66. void UART1_IRQHandler(void)
  67. {
  68.     volatile uint8_t i;


  69.     switch(UART1_GetITFlag())
  70.     {
  71.         case UART_II_LINE_STAT: // 线路状态错误
  72.         {
  73.             UART1_GetLinSTA();
  74.             break;
  75.         }


  76.         case UART_II_RECV_RDY: // 数据达到设置触发点
  77.             for(i = 0; i != trigB; i++)
  78.             {
  79.                 RxBuff[i] = UART1_RecvByte();
  80.                 UART1_SendByte(RxBuff[i]);
  81.             }
  82.             break;


  83.         case UART_II_RECV_TOUT: // 接收超时,暂时一帧数据接收完成
  84.             i = UART1_RecvString(RxBuff);
  85.             UART1_SendString(RxBuff, i);
  86.             break;


  87.         case UART_II_THR_EMPTY: // 发送缓存区空,可继续发送
  88.             break;


  89.         case UART_II_MODEM_CHG: // 只支持串口0
  90.             break;


  91.         default:
  92.             break;
  93.     }
  94. }


1414268902bd73bcea.png













您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

46

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部