找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1261|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

HK32單片機串口打印程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:302293 發(fā)表于 2024-3-26 10:42 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
   串口打印文本

  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  Alexander
  5.   * @version V1.0
  6.   * @date    2022-xx-xx
  7.   * @brief   串口中斷接收測試
  8.   ******************************************************************************
  9.   * @attention
  10.   *
  11.   * 實驗平臺:HK32F030M開發(fā)板
  12.   *
  13.   ******************************************************************************
  14.   */
  15. #include "hk32f030m.h"
  16. #include "bsp_usart.h"
  17. #include "bsp_led.h"

  18. static void Show_Message(void);
  19. enum{
  20.         /* ftp */
  21.     FTP_TEST = 10,

  22. };
  23. struct oam_excute_st
  24. {
  25.      int (*doit)(char*, char* , int *);
  26.      int (*dumpit)(char*, char* , int *, int );
  27. };
  28. extern struct oam_excute_st * oam_execute ;
  29. int ftp_test (char *buf, char *outbuf, int *len){

  30.   printf("hello,world\n");
  31. //  return 0;
  32. }
  33. struct oam_excute_st ftp_oam_table[]=
  34. {
  35.         [FTP_TEST]   = {.doit = ftp_test},

  36. };


  37. /**
  38.   * @brief  主函數(shù)
  39.   * @param  無
  40.   * @retval 無
  41.   */
  42. int main(void)
  43. {       
  44.   char ch,i;
  45.   
  46.   /* 初始化RGB彩燈 */
  47.   LED_GPIO_Config();
  48.   
  49.   /* 初始化USART 配置模式為 115200 8-N-1 */
  50.   USART_Config();
  51.        
  52.   /* 打印指令輸入提示信息 */
  53. //  Show_Message();
  54.   while(1)
  55.         {       
  56.     /* 獲取字符指令 */
  57. //    ch=getchar();
  58. //    printf("接收到字符:%c\n",ch);
  59. //      printf("   指令   ------    LED狀態(tài) \n");
  60.   ftp_oam_table[FTP_TEST].doit(NULL,NULL,&i);
  61.     }   
  62.         }       


  63. /**
  64.   * @brief  打印指令輸入提示信息
  65.   * @param  無
  66.   * @retval 無
  67.   */
  68. static void Show_Message(void)
  69. {
  70.   printf("\r\n   這是一個通過串口通信指令控制LED實驗 \n");
  71.   printf("使用  USART  參數(shù)為:%d 8-N-1 \n",DEBUG_USART_BAUDRATE);
  72.   printf("開發(fā)板接到指令后控制LED狀態(tài),指令對應(yīng)如下:\n");
  73.   printf("   指令   ------    LED狀態(tài) \n");
  74.   printf("     1    ------    LED1亮 \n");
  75.   printf("     2    ------    LED2亮 \n");
  76.   printf("     3    ------    LED3亮 \n");
  77.   printf("     4    ------    LED1滅 \n");
  78.   printf("     5    ------    LED2滅 \n");
  79.   printf("     6    ------    LED3滅 \n");
  80.   printf("     7    ------    LED1反轉(zhuǎn) \n");
  81.   printf("     8    ------    LED2反轉(zhuǎn) \n");
  82.   printf("     9    ------    LED3反轉(zhuǎn) \n");
  83. }



  84. #ifdef  USE_FULL_ASSERT
  85. /**
  86.   * @brief  Reports the name of the source file and the source line number
  87.   *         where the assert_param error has occurred.
  88.   * @param  file: pointer to the source file name
  89.   * @param  line: assert_param error line source number
  90.   * @retval None
  91.   */
  92. void assert_failed(char* file , uint32_t line)
  93. {
  94.   /* User can add his own implementation to report the file name and line number,
  95.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */       
  96.        /* Infinite loop */
  97.        
  98.         while (1)
  99.   {               
  100.   }
  101. }
  102. #endif /* USE_FULL_ASSERT */
復(fù)制代碼

原理圖: 無
仿真: 無
代碼: 程序.7z (173.59 KB, 下載次數(shù): 2)

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表