[DemoCode下载] NuTinySDKM451自带的例子

[复制链接]
515|3
 楼主| yiyigirl2014 发表于 2019-4-30 21:31 | 显示全部楼层 |阅读模式
  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. * $Date: 15/09/02 10:03a $
  5. * [url=home.php?mod=space&uid=247401]@brief[/url]    Toggle PC.9 to turn on / off the board LED
  6. *
  7. * @note
  8. * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved.
  9. *
  10. ******************************************************************************/
  11. #include <stdio.h>
  12. #include "M451Series.h"

  13. #define HCLK_CLOCK       72000000


  14. void SYS_Init(void)
  15. {
  16.     /*---------------------------------------------------------------------------------------------------------*/
  17.     /* Init System Clock                                                                                       */
  18.     /*---------------------------------------------------------------------------------------------------------*/
  19.     /* Unlock protected registers */
  20.     SYS_UnlockReg();

  21.     /* Enable HIRC clock (Internal RC 22.1184MHz) */
  22.     CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

  23.     /* Wait for HIRC clock ready */
  24.     CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

  25.     /* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */
  26.     CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

  27.     /* Enable HXT clock (external XTAL 12MHz) */
  28.     CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);

  29.     /* Wait for HXT clock ready */
  30.     CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);

  31.     /* Set core clock as HCLK_CLOCK */
  32.     CLK_SetCoreClock(HCLK_CLOCK);

  33.     /* Update System Core Clock */
  34.     /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
  35.     SystemCoreClockUpdate();

  36.     /*---------------------------------------------------------------------------------------------------------*/
  37.     /* Init I/O Multi-function                                                                                 */
  38.     /*---------------------------------------------------------------------------------------------------------*/
  39.     /* Set GPD multi-function pins for UART0 RXD and TXD */
  40.     SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD6MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
  41.     SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD6MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);

  42.     /* Lock protected registers */
  43.     SYS_LockReg();
  44. }


  45. /*---------------------------------------------------------------------------------------------------------*/
  46. /* MAIN function                                                                                           */
  47. /*---------------------------------------------------------------------------------------------------------*/
  48. int main(void)
  49. {
  50.     /* Init System, IP clock and multi-function I/O
  51.        In the end of SYS_Init() will issue SYS_LockReg()
  52.        to lock protected register. If user want to write
  53.        protected register, please issue SYS_UnlockReg()
  54.        to unlock protected register if necessary */
  55.     SYS_Init();

  56.     /* Select SysTick clock source as HXT */
  57.     CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLKSEL_HXT);

  58.     /* Configure PC.9 as Output mode */
  59.     GPIO_SetMode(PC, BIT9, GPIO_MODE_OUTPUT);

  60.     while(1)
  61.     {
  62.         /* Configure PC.9 to low */
  63.         PC9 = 0;
  64.         /* Delay 200 ms */
  65.         CLK_SysTickDelay(200000);

  66.         /* Configure PC.9 to high */
  67.         PC9 = 1;
  68.         /* Delay 200 ms */
  69.         CLK_SysTickDelay(200000);
  70.     }

  71. }




 楼主| yiyigirl2014 发表于 2019-4-30 21:31 | 显示全部楼层
开发板出厂自带的一个LED闪烁的例子,非常容易。
 楼主| yiyigirl2014 发表于 2019-4-30 21:31 | 显示全部楼层
包含了基本的时钟配置
延时函数
以及IO的输出操作。
zhuomuniao110 发表于 2019-4-30 21:37 | 显示全部楼层
闪灯操作。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

230

主题

3676

帖子

10

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