[DemoCode下载] 最简单的使用串口的例子

[复制链接]
510|0
 楼主| 小明的同学 发表于 2019-6-28 21:45 | 显示全部楼层 |阅读模式
  1. /******************************************************************************
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
  4. * $Revision: 4 $
  5. * $Date: 15/09/02 10:05a $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Software Development Template.
  7. * @note
  8. * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved.
  9. *****************************************************************************/
  10. #include <stdio.h>
  11. #include "M451Series.h"

  12. void SYS_Init(void)
  13. {
  14.     /*---------------------------------------------------------------------------------------------------------*/
  15.     /* Init System Clock                                                                                       */
  16.     /*---------------------------------------------------------------------------------------------------------*/

  17.     /* Enable UART module clock */
  18.     CLK_EnableModuleClock(UART0_MODULE);

  19.     /* Update System Core Clock */
  20.     /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock and cyclesPerUs automatically. */
  21.     SystemCoreClockUpdate();

  22.     /*---------------------------------------------------------------------------------------------------------*/
  23.     /* Init I/O Multi-function                                                                                 */
  24.     /*---------------------------------------------------------------------------------------------------------*/
  25.     /* Set PD multi-function pins for UART0 RXD and TXD */
  26.     SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD0MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
  27.     SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD0MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);
  28. }


  29. int main()
  30. {

  31.     int8_t ch;

  32.     /* Unlock protected registers */
  33.     SYS_UnlockReg();

  34.     SYS_Init();

  35.     /* Lock protected registers */
  36.     SYS_LockReg();

  37.     /* Init UART0 to 115200-8n1 for print message */
  38.     UART_Open(UART0, 115200);

  39.     printf("\n");
  40.     printf("Simple Demo Code\n\n");

  41.     printf("Please Input Any Key\n\n");

  42.     do
  43.     {
  44.         printf("Input: ");
  45.         ch = getchar();
  46.         printf("%c\n", ch);
  47.     }
  48.     while(1);

  49. }

  50. /*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/


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

本版积分规则

159

主题

1640

帖子

2

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