在 main.c 中放入下面的程序:
#include <stdio.h>
#include "M451Series.h"
#define HCLK_CLOCK 72000000
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Unlock protected registers */
SYS_UnlockReg();
/* Enable HIRC clock (Internal RC 22.1184MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
/* Wait for HIRC clock ready */
CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
/* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));
/* Enable HXT clock (external XTAL 12MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Wait for HXT clock ready */
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
/* Set core clock as HCLK_CLOCK */
CLK_SetCoreClock(HCLK_CLOCK);
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
SystemCoreClockUpdate();
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set GPD multi-function pins for UART0 RXD and TXD */
SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD6MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD6MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);
/* Lock protected registers */
SYS_LockReg();
}
/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
int i=0;
SYS_Init();
/* Select SysTick clock source as HXT */
CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLKSEL_HXT);
/*Configure PC.9 as Output mode */
GPIO_SetMode(PC, BIT9, GPIO_MODE_OUTPUT);
GPIO_SetMode(PC, BIT10, GPIO_MODE_OUTPUT);
GPIO_SetMode(PC, BIT11, GPIO_MODE_OUTPUT);
/*PWM_ConfigOutputChannel(PWM0, PWM_CH_0_MASK, 100, 50);
PWM_Start(PWM0,BIT0);
*/
while(1)
{
/* Configure PC.9 to low */
PC9 = 1; // PC10 = 0;PC11 = 0;
/* Delay 200 ms */
CLK_SysTickDelay( 200-i);
/* Configure PC.9 to high */
PC9 = 0;//PC10 = 1; PC11 = 1;
/* Delay 200 ms */
CLK_SysTickDelay(i);
i++;
if(++i == 200 ) i=0;
}
}
/**************************************************************************//**
* @file main.c
* @version V1.00
* $Date: 16/03/19 10:51a $
* @brief Toggle PC.9 to turn on / off the board LED
*
* @note
* Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "M451Series.h"
#define HCLK_CLOCK 72000000
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Unlock protected registers */
SYS_UnlockReg();
/* Enable HIRC clock (Internal RC 22.1184MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
/* Wait for HIRC clock ready */
CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
/* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));
/* Enable HXT clock (external XTAL 12MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Wait for HXT clock ready */
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
/* Set core clock as HCLK_CLOCK */
CLK_SetCoreClock(HCLK_CLOCK);
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
SystemCoreClockUpdate();
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set GPD multi-function pins for UART0 RXD and TXD */
SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD6MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD6MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);
/* Lock protected registers */
SYS_LockReg();
}
/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
int i=0;
SYS_Init();
/* Select SysTick clock source as HXT */
CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLKSEL_HXT);
/*Configure PC.9 as Output mode */
GPIO_SetMode(PC, BIT9, GPIO_MODE_OUTPUT);
GPIO_SetMode(PC, BIT10, GPIO_MODE_OUTPUT);
GPIO_SetMode(PC, BIT11, GPIO_MODE_OUTPUT);
/*PWM_ConfigOutputChannel(PWM0, PWM_CH_0_MASK, 100, 50);
PWM_Start(PWM0,BIT0);
*/
while(1)
{
/* Configure PC.9 to low */
PC9 = 1; // PC10 = 0;PC11 = 0;
/* Delay 200 ms */
CLK_SysTickDelay( 200-i);
/* Configure PC.9 to high */
PC9 = 0;//PC10 = 1; PC11 = 1;
/* Delay 200 ms */
CLK_SysTickDelay(i);
i++;
if(++i == 200 ) i=0;
}
}
/**************************************************************************//**
* @file main.c
* @version V1.00
* $Date: 16/03/19 10:51a $
* @brief Toggle PC.9 to turn on / off the board LED
*
* @note
* Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "M451Series.h"
#define HCLK_CLOCK 72000000
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Unlock protected registers */
SYS_UnlockReg();
/* Enable HIRC clock (Internal RC 22.1184MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
/* Wait for HIRC clock ready */
CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
/* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));
/* Enable HXT clock (external XTAL 12MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Wait for HXT clock ready */
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
/* Set core clock as HCLK_CLOCK */
CLK_SetCoreClock(HCLK_CLOCK);
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
SystemCoreClockUpdate();
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set GPD multi-function pins for UART0 RXD and TXD */
SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD6MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD6MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);
/* Lock protected registers */
SYS_LockReg();
}
/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
int i=0;
SYS_Init();
/* Select SysTick clock source as HXT */
CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLKSEL_HXT);
/*Configure PC.9 as Output mode */
GPIO_SetMode(PC, BIT9, GPIO_MODE_OUTPUT);
GPIO_SetMode(PC, BIT10, GPIO_MODE_OUTPUT);
GPIO_SetMode(PC, BIT11, GPIO_MODE_OUTPUT);
/*PWM_ConfigOutputChannel(PWM0, PWM_CH_0_MASK, 100, 50);
PWM_Start(PWM0,BIT0);
*/
while(1)
{
/* Configure PC.9 to low */
PC9 = 1; // PC10 = 0;PC11 = 0;
/* Delay 200 ms */
CLK_SysTickDelay( 200-i);
/* Configure PC.9 to high */
PC9 = 0;//PC10 = 1; PC11 = 1;
/* Delay 200 ms */
CLK_SysTickDelay(i);
i++;
if(++i == 200 ) i=0;
}
}
|