[DemoCode下载] M451的LED操作

[复制链接]
398|2
 楼主| xuanhuanzi 发表于 2019-4-30 21:25 | 显示全部楼层 |阅读模式
LED, ck, UART, TE, se
  1. /**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V3.00
  4. * $Revision: 3 $
  5. * $Date: 15/09/02 10:03a $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Demonstrate how to set GPIO pin mode and use pin data input/output control.
  7. * @note
  8. * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved.
  9. *
  10. ******************************************************************************/
  11. #include "stdio.h"
  12. #include "M451Series.h"
  13. #include "NuEdu-Basic01.h"

  14. #define PLL_CLOCK       72000000


  15. void SYS_Init(void)
  16. {
  17.     /*---------------------------------------------------------------------------------------------------------*/
  18.     /* Init System Clock                                                                                       */
  19.     /*---------------------------------------------------------------------------------------------------------*/

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

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

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

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

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

  30.     /* Set core clock as PLL_CLOCK from PLL */
  31.     CLK_SetCoreClock(PLL_CLOCK);

  32.     /* Enable UART module clock */
  33.     CLK_EnableModuleClock(UART0_MODULE);

  34.     /* Select UART module clock source as HXT and UART module clock divider as 1 */
  35.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));

  36.     /*---------------------------------------------------------------------------------------------------------*/
  37.     /* Init I/O Multi-function                                                                                 */
  38.     /*---------------------------------------------------------------------------------------------------------*/

  39.     /* Set PD multi-function pins for UART0 RXD(PD.6) and TXD(PD.1) */
  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. }

  43. void UART0_Init()
  44. {
  45.     /*---------------------------------------------------------------------------------------------------------*/
  46.     /* Init UART                                                                                               */
  47.     /*---------------------------------------------------------------------------------------------------------*/
  48.     /* Reset UART module */
  49.     SYS_ResetModule(UART0_RST);

  50.     /* Configure UART0 and set UART0 baud rate */
  51.     UART_Open(UART0, 115200);
  52. }

  53. /*---------------------------------------------------------------------------------------------------------*/
  54. /*  Main Function                                                                                          */
  55. /*---------------------------------------------------------------------------------------------------------*/
  56. int32_t main(void)
  57. {
  58.     int i, j;
  59.     /* Unlock protected registers */
  60.     SYS_UnlockReg();

  61.     /* Init System, peripheral clock and multi-function I/O */
  62.     SYS_Init();

  63.     /* Lock protected registers */
  64.     SYS_LockReg();

  65.     /* Init UART0 for printf */
  66.     UART0_Init();

  67.     printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);

  68.     printf("LED test\n\r");

  69.     Initial_LED();

  70.     while(1)
  71.     {
  72.         for(i = 0; i < 9; i++)
  73.         {
  74.             Write_LED_Bar(i);
  75.             for(j = 0; j < 600; j++)
  76.                 CLK_SysTickDelay(1000);
  77.         }
  78.     }
  79. }


 楼主| xuanhuanzi 发表于 2019-4-30 21:25 | 显示全部楼层
这个应该算是入门操作
 楼主| xuanhuanzi 发表于 2019-4-30 21:25 | 显示全部楼层
相当于Hello world
您需要登录后才可以回帖 登录 | 注册

本版积分规则

183

主题

2331

帖子

3

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