- /*---------------------------------------------------------------------------------------------------------*/
- /* */
- /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- //***********************************************************************************************************
- // Nuvoton Technology Corp.
- // E-mail: MicroC-8bit@nuvoton.com
- //***********************************************************************************************************
- // Application: Timer2 Function
- // This file set up timer 2 in auto-reload mode (16 bits timer) with a hardware gate.
- // The 16-bits register consist of all 8 bits of TH2 and all 8 bits of TL2.
- // Timer2 flag will be set when times out. P1.4 is going to be toggled by polling.
- //
- // Output : P1.4 & P2.1 toggle when timer0 flag is set
- //***********************************************************************************************************
- //------------------------- <<< Use Configuration Wizard in Context Menu >>> --------------------------------
- // <o0.6> UART pin Select
- // <0=> Select P1.0, P1.1 as UART pin(default)
- // <1=> Select P2.6, P2.7 as UART pin(28 pin only)
- //-------------------------------- <<< end of configuration section >>> -------------------------------------
- #define Uart_Port_Sel 0x00
- #include <stdio.h>
- #include "N79E715.h"
- #include "Typedef.h"
- #include "Define.h"
- #include "Common.h"
- #include "Delay.h"
- #include "Version.h"
- //-----------------------------------------------------------------------------------------------------------
- void main(void)
- {
- AUXR1 |= Uart_Port_Sel; // Select P10/P11 as UART pin(default)
- InitialUART0_Timer1(9600); // 9600 Baud Rate [url=home.php?mod=space&uid=72445]@[/url] 11.0592MHz
- Show_Version_Number_To_PC();
- printf ("\n*===================================================================");
- printf ("\n* Name: N79E715 Series Timer2 Sample Code.");
- printf ("\n*===================================================================");
- printf ("\nTimer2 Demo Start.");
- printf ("\nP1.4 toggle by polling.");
- printf ("\nP2.1 toggle by polling.\n");
- T2MOD = 0x90; // Enabled auto-reload and timer2 clock divider is 1/8
- TH2 = 0x10; // Initial values
- TL2 = 0x00;
- RCOMP2L = TL2 ; // Reload values initialize
- RCOMP2H = TH2 ;
- EA = 1; // Enable interrupts
- TR2 = 1; // Timer2 run
- while(1)
- {
- while(!TF2);
- P14 = ~P14; // P1.4 toggle by polling
- P21 = ~P21; // P2.1 toggle by polling
- TF2 = 0; // Clear timer2 flag(TF2)
- }
- }
- //-----------------------------------------------------------------------------------------------------------
|