- /******************************************************************************
- * [url=home.php?mod=space&uid=288409]@file[/url] main.c
- * [url=home.php?mod=space&uid=895143]@version[/url] V1.00
- * $Revision: 2 $
- * $Date: 15/04/08 11:44a $
- * [url=home.php?mod=space&uid=247401]@brief[/url] Demonstrate the timer 0 toggle out function on pin P3.4.
- *
- * @note
- * Copyright (C) 2015 Nuvoton Technology Corp. All rights reserved.
- *****************************************************************************/
- #include <stdio.h>
- #include "NM1200_NM1100.h"
- void SYS_Init(void)
- {
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init System Clock */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Unlock protected registers */
- SYS_UnlockReg();
- /* Read User Config to select internal high speed RC */
- SystemInit();
- /* Enable external 12MHz XTAL (UART), and HIRC */
- CLK->PWRCTL = CLK_PWRCTL_XTL12M | CLK_PWRCTL_HIRCEN_Msk;
- /* Waiting for clock ready */
- CLK_WaitClockReady(CLK_STATUS_XTLSTB_Msk | CLK_STATUS_HIRCSTB_Msk);
- /* Enable UART and Timer 0 clock */
- CLK->APBCLK = CLK_APBCLK_UART0CKEN_Msk | CLK_APBCLK_TMR0CKEN_Msk;
- /* Select UART clock source from external crystal*/
- CLK->CLKSEL1 = (CLK->CLKSEL1 & ~CLK_CLKSEL1_UART0SEL_Msk) | CLK_CLKSEL1_UART0SEL_XTAL;
- /* Update System Core Clock */
- /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock and CycylesPerUs automatically. */
- SystemCoreClockUpdate();
- /*---------------------------------------------------------------------------------------------------------*/
- /* Init I/O Multi-function */
- /*---------------------------------------------------------------------------------------------------------*/
- /* Set P1 multi-function pins for UART RXD, TXD */
- SYS->P0_MFP = SYS_MFP_P00_TXD | SYS_MFP_P01_RXD;
- /* Set P3 multi-function pins for Timer toggle output pin */
- SYS->P3_MFP = SYS_MFP_P34_T0;
- /* Lock protected registers */
- SYS_LockReg();
- }
- int main(void)
- {
- /* Init System, IP clock and multi-function I/O
- In the end of SYS_Init() will issue SYS_LockReg()
- to lock protected register. If user want to write
- protected register, please issue SYS_UnlockReg()
- to unlock protected register if necessary */
- SYS_Init();
- /* Init UART to 115200-8n1 for print message */
- UART_Open(UART0, 115200);
- printf("\nThis sample code use timer 0 to generate 1kHz toggle output to T0 pin (P3.4) \n");
- /* To generate 1kHZ toggle output, timer frequency must set to 2000Hz.
- Because toggle output state change on every timer timeout event */
- TIMER_Open(TIMER0, TIMER_TOGGLE_MODE, 2000);
- TIMER_Start(TIMER0);
- while(1);
- }
- /*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
|