不知道翻译的对不对,请高手来讲解啊
/**************************************************************************//**
* [url=home.php?mod=space&uid=288409]@file[/url] main.c
* [url=home.php?mod=space&uid=895143]@version[/url] V1.00
* $Date: 14/07/31 1:44p $
* [url=home.php?mod=space&uid=247401]@brief[/url] NUC472/NUC442 General Purpose I/O Driver Sample Code
* Connect PB.3 and PD.7 to test IO In/Out
* Test PB2, PC5, PA0(INT0) and PF0(INT5) interrupts
*
* @note
* Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "NUC472_442.h"
#include "gpio.h"
#define PLLCON_SETTING CLK_PLLCON_84MHz_HXT
#define PLL_CLOCK 84000000
/**
* @brief GPIO IRQ
*
* @param None
*
* [url=home.php?mod=space&uid=266161]@return[/url] None
*
* [url=home.php?mod=space&uid=1543424]@Details[/url] The GPIO default IRQ, declared in startup_NUC472_442.s.
*/
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Unlock protected registers */
SYS_UnlockReg();
/* Enable External XTAL (4~24 MHz) */
CLK->PWRCTL |= CLK_PWRCTL_HXTEN_Msk; // XTAL12M (HXT) Enabled
/* Waiting for 12MHz clock ready */
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
/* Switch HCLK clock source to XTAL */
CLK->CLKSEL0 &= ~CLK_CLKSEL0_HCLKSEL_Msk;
CLK->CLKSEL0 |= CLK_CLKSEL0_HCLKSEL_HXT;
/* Enable IP clock */
CLK->APBCLK0 |= CLK_APBCLK0_UART0CKEN_Msk; // UART0 Clock Enable
CLK->APBCLK0 |= CLK_APBCLK0_RTCCKEN_Msk; // RTC Clock Enable
/* Select IP clock source */
CLK->CLKSEL1 &= ~CLK_CLKSEL1_UARTSEL_Msk;
CLK->CLKSEL1 |= (0x0 << CLK_CLKSEL1_UARTSEL_Pos);// Clock source from external 12 MHz or 32 KHz crystal clock
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
SystemCoreClockUpdate();
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set PG multi-function pins for UART0 RXD, TXD */
SYS->GPG_MFPL &= ~(SYS_GPG_MFPL_PG1MFP_Msk | SYS_GPG_MFPL_PG2MFP_Msk);
SYS->GPG_MFPL |= (SYS_GPG_MFPL_PG1MFP_UART0_RXD | SYS_GPG_MFPL_PG2MFP_UART0_TXD);
/* Lock protected registers */
// SYS_LockReg();
}
void RTC_init(void)
{
S_RTC_TIME_DATA_T sRTC_Time;
/* Time Setting */
sRTC_Time.u32Year = 2016;
sRTC_Time.u32Month = 12;
sRTC_Time.u32Day = 13;
sRTC_Time.u32Hour = 12;
sRTC_Time.u32Minute = 59;
sRTC_Time.u32Second = 50;
sRTC_Time.u32DayOfWeek = RTC_TUESDAY;
sRTC_Time.u32TimeScale = RTC_CLOCK_24;
RTC_Open(&sRTC_Time);
RTC_EnableTamperDetection(RTC_TAMPER_0, 1, 0, 1, 1);
RTC_EnableTamperDetection(RTC_TAMPER_1, 1, 0, 1, 1);
}
/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
void RTC_AccessEnable()
{
RTC->RWEN = RTC_WRITE_KEY;
while(!(RTC->RWEN & RTC_RWEN_RWENF_Msk));
}
int main (void)
{
int32_t Spare_Data, i;
SYS_Init();
/* Init UART to 115200-8n1 for print message */
UART_Open(UART0, 115200);
printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);
SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA1MFP_Msk | SYS_GPA_MFPL_PA2MFP_Msk | SYS_GPA_MFPL_PA0MFP_Msk);
GPIO_SetMode(PA, (BIT0 | BIT1 | BIT2), GPIO_MODE_OUTPUT);
PA0 = 0;
PA1 = 0;
PA2 = 0;
SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA1MFP_Msk | SYS_GPA_MFPL_PA2MFP_Msk | SYS_GPA_MFPL_PA0MFP_Msk);
SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA0MFP_TAMPER0 | SYS_GPA_MFPL_PA1MFP_TAMPER1);
RTC_init();
// Enable spare register
RTC_EnableSpareAccess();
// Write spare register
for(i = 0; i < 24; i++) {
RTC_AccessEnable();
RTC_WRITE_SPARE_REGISTER(i, i+1);
while(!(RTC->SPRCTL & RTC_SPRCTL_SPRRWRDY_Msk));
}
while (1)
{
// Check spare register data
for(i = 0; i < 24; i++)
{
RTC_AccessEnable();
Spare_Data = RTC_READ_SPARE_REGISTER(i);
if(Spare_Data != i+1)
{
PA2 = 0;
}
else
{
PA2 = 1;
}
}
}
}
|