找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 146|回复: 0
收起左侧

HK32单片机串口打印程序

[复制链接]
ID:302293 发表于 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开发板
  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  主函数
  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状态 \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  参数为:%d 8-N-1 \n",DEBUG_USART_BAUDRATE);
  72.   printf("开发板接到指令后控制LED状态,指令对应如下:\n");
  73.   printf("   指令   ------    LED状态 \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反转 \n");
  81.   printf("     8    ------    LED2反转 \n");
  82.   printf("     9    ------    LED3反转 \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 */
复制代码

原理图: 无
仿真: 无
代码: 程序.7z (173.59 KB, 下载次数: 2)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表