#include "stdio.h"
#include "NuMicro.h"
static void SYS_Init(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Enable HIRC */
CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
/* Waiting for HIRC clock ready */
CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
/* Switch HCLK clock source to HIRC */
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));
/* Set both PCLK0 and PCLK1 as HCLK/2 */
CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
SystemCoreClockUpdate();
/* Lock protected registers */
SYS_LockReg();
}
static void delay_ms(uint16_t nDelay)
{
uint16_t nIndex;
for(nIndex = 0; nIndex < nDelay; nIndex++)
{
CLK_SysTickDelay(1000);//delay one ms
}
}
int32_t main(void)
{
/* Init System, IP clock and multi-function I/O. */
SYS_Init();
GPIO_SetMode(PB,BIT14,GPIO_MODE_OUTPUT);
while(1){
PB14 = 1;
delay_ms(1000);
PB14 = 0;
delay_ms(1000);
}
}
|