[DemoCode下载] M031 入门 点亮板载LED

[复制链接]
1255|1
 楼主| 1988020566 发表于 2024-6-22 18:22 | 显示全部楼层 |阅读模式
sy, ST, ck, TE, LED


  1. #include "stdio.h"
  2. #include "NuMicro.h"


  3. static void SYS_Init(void)
  4. {
  5.     /* Unlock protected registers */
  6.     SYS_UnlockReg();

  7.     /* Enable HIRC */
  8.     CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

  9.     /* Waiting for HIRC clock ready */
  10.     CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

  11.     /* Switch HCLK clock source to HIRC */
  12.     CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

  13.     /* Set both PCLK0 and PCLK1 as HCLK/2 */
  14.     CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);

  15.     /* Update System Core Clock */
  16.     /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
  17.     SystemCoreClockUpdate();

  18.     /* Lock protected registers */
  19.     SYS_LockReg();
  20. }


  21. static void delay_ms(uint16_t nDelay)
  22. {
  23.     uint16_t nIndex;
  24.     for(nIndex = 0; nIndex < nDelay; nIndex++)
  25.     {
  26.         CLK_SysTickDelay(1000);//delay one ms
  27.     }
  28. }

  29. int32_t main(void)
  30. {

  31.     /* Init System, IP clock and multi-function I/O. */
  32.     SYS_Init();
  33.    
  34.     GPIO_SetMode(PB,BIT14,GPIO_MODE_OUTPUT);
  35.     while(1){
  36.       PB14 = 1;
  37.       delay_ms(1000);
  38.       PB14 = 0;
  39.       delay_ms(1000);
  40.     }
  41. }


ddw315 发表于 2024-6-23 09:33 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

423

主题

11039

帖子

7

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