[DemoCode下载] M480系列BSP去年年底更新了,用到的兄弟别忘了去更

[复制链接]
905|2
 楼主| zhuotuzi 发表于 2023-2-10 09:57 | 显示全部楼层 |阅读模式
3674963e5a43a97d19.png

https://www.nuvoton.com/resource-download.jsp?tp_GUID=SW1820210122093510
基于CMSIS 4.5.0版本的M480系列软件包。它支持IAR、Keil和Eclipse开发环境,并提供驱动程序和示例代码。NuMaker-PFM-M480的示例源代码。详情请下载并解压。
  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. * [url=home.php?mod=space&uid=247401]@brief[/url]    Show how to set GPIO pin mode and use pin data input/output control.
  5. *
  6. * [url=home.php?mod=space&uid=17282]@CopyRight[/url] (C) 2013~2015 Nuvoton Technology Corp. All rights reserved.
  7. *
  8. ******************************************************************************/
  9. #include "stdio.h"
  10. #include "NuMicro.h"


  11. #define PLL_CLOCK       192000000


  12. void SYS_Init(void)
  13. {

  14.     /* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode */
  15.     PF->MODE &= ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk);

  16.     /* Enable HXT clock (external XTAL 12MHz) */
  17.     CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);

  18.     /* Wait for HXT clock ready */
  19.     CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);

  20.     /* Set core clock as PLL_CLOCK from PLL */
  21.     CLK_SetCoreClock(PLL_CLOCK);

  22.     /* Set PCLK0/PCLK1 to HCLK/2 */
  23.     CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);

  24.     /* Enable UART module clock */
  25.     CLK_EnableModuleClock(UART0_MODULE);

  26.     /* Select UART module clock source as HXT and UART module clock divider as 1 */
  27.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HXT, CLK_CLKDIV0_UART0(1));

  28.     /* Set GPB multi-function pins for UART0 RXD and TXD */
  29.     SYS->GPB_MFPH &= ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk);
  30.     SYS->GPB_MFPH |= (SYS_GPB_MFPH_PB12MFP_UART0_RXD | SYS_GPB_MFPH_PB13MFP_UART0_TXD);

  31. }

  32. void UART0_Init()
  33. {
  34.     /* Configure UART0 and set UART0 baud rate */
  35.     UART_Open(UART0, 115200);
  36. }

  37. int32_t main(void)
  38. {

  39.     int32_t i32Err, i32TimeOutCnt;

  40.     /* Unlock protected registers */
  41.     SYS_UnlockReg();

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

  44.     /* Lock protected registers */
  45.     SYS_LockReg();

  46.     /* Init UART0 for printf */
  47.     UART0_Init();

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

  49.     printf("+-------------------------------------------------+\n");
  50.     printf("|    PB.3(Output) and PD.8(Input) Sample Code     |\n");
  51.     printf("+-------------------------------------------------+\n\n");

  52.     /*-----------------------------------------------------------------------------------------------------*/
  53.     /* GPIO Basic Mode Test --- Use Pin Data Input/Output to control GPIO pin                              */
  54.     /*-----------------------------------------------------------------------------------------------------*/
  55.     printf("  >> Please connect PB.3 and PD.8 first << \n");
  56.     printf("     Press any key to start test by using [Pin Data Input/Output Control] \n\n");
  57.     getchar();

  58.     /* Configure PB.3 as Output mode and PD.8 as Input mode then close it */
  59.     GPIO_SetMode(PB, BIT3, GPIO_MODE_OUTPUT);
  60.     GPIO_SetMode(PD, BIT8, GPIO_MODE_INPUT);

  61.     i32Err = 0;
  62.     printf("GPIO PB.3(output mode) connect to PD.8(input mode) ......");

  63.     /* Use Pin Data Input/Output Control to pull specified I/O or get I/O pin status */
  64.     /* Set PB.3 output pin value is low */
  65.     PB3 = 0;

  66.     /* Set time out counter */
  67.     i32TimeOutCnt = 100;

  68.     /* Wait for PD.8 input pin status is low for a while */
  69.     while(PD8 != 0)
  70.     {
  71.         if(i32TimeOutCnt > 0)
  72.         {
  73.             i32TimeOutCnt--;
  74.         }
  75.         else
  76.         {
  77.             i32Err = 1;
  78.             break;
  79.         }
  80.     }

  81.     /* Set PB.3 output pin value is high */
  82.     PB3 = 1;

  83.     /* Set time out counter */
  84.     i32TimeOutCnt = 100;

  85.     /* Wait for PD.8 input pin status is high for a while */
  86.     while(PD8 != 1)
  87.     {
  88.         if(i32TimeOutCnt > 0)
  89.         {
  90.             i32TimeOutCnt--;
  91.         }
  92.         else
  93.         {
  94.             i32Err = 1;
  95.             break;
  96.         }
  97.     }

  98.     /* Print test result */
  99.     if(i32Err)
  100.     {
  101.         printf("  [FAIL].\n");
  102.     }
  103.     else
  104.     {
  105.         printf("  [OK].\n");
  106.     }

  107.     /* Configure PB.3 and PD.8 to default Quasi-bidirectional mode */
  108.     GPIO_SetMode(PB, BIT3, GPIO_MODE_QUASI);
  109.     GPIO_SetMode(PD, BIT8, GPIO_MODE_QUASI);

  110.     while(1);

  111. }




幸福小强 发表于 2023-2-10 13:40 | 显示全部楼层
保持更新,防止BUG。
中国龙芯CDX 发表于 2023-2-13 10:12 | 显示全部楼层
更新跟上问题相对会少一点
您需要登录后才可以回帖 登录 | 注册

本版积分规则

214

主题

3375

帖子

7

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