- /*---------------------------------------------------------------------------------------------------------*/
- /* */
- /* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved. */
- /* */
- /*---------------------------------------------------------------------------------------------------------*/
- //***********************************************************************************************************
- // Nuvoton Technology Corp.
- // E-mail: MicroC-8bit@nuvoton.com
- //***********************************************************************************************************
- // Application: WDT Function
- // Set watch counter and enable WDT interrupt. WDT ISR will be execute when WDT time out.
- //
- // Output : P1.4 & P2.1 toggle by WDT interrupt
- //***********************************************************************************************************
- //========================================= How to set WDT register =========================================
- //
- // 1.WDT time-out period is 64 /(Fwck + Prescalar);
- //
- // 2.Fwck is frequency of WDT clock source
- //
- // 3.Prescalar = WDCON0 & 0x07
- //===========================================================================================================
- //------------------------- <<< Use Configuration Wizard in Context Menu >>> --------------------------------
- //
- //<o0.0..2> WDT Prescalar Select
- // <0=> 1/1 <1=> 1/2 <2=> 1/8 <3=> 1/16
- // <4=> 1/32 <5=> 1/64 <6=> 1/128 <7=> 1/256
- // <o1.6> UART pin Select
- // <0=> Select P1.0, P1.1 as UART pin <1=> Select P2.6, P2.7 as UART pin(28 pin only)
- //-------------------------------- <<< end of configuration section >>> -------------------------------------
- #define WDT_CLK_DIV 0x01
- #define Uart_Port_Sel 0x00
- #include <stdio.h>
- #include "N79E715.h"
- #include "Typedef.h"
- #include "Define.h"
- #include "Common.h"
- #include "Delay.h"
- #include "WDT.h"
- #include "Version.h"
- bit EA_Save_bit;
- //-----------------------------------------------------------------------------------------------------------
- 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 WDT Sample Code.");
- printf ("\n*===================================================================");
- printf ("\nWDT Demo Start.");
- printf ("\nP1.4 & P2.1 toggle by polling.\n");
- EA_Save_bit = EA;
- EA = 0;
- TA = 0xAA;
- TA = 0x55;
- WDCON0 &= 0xf8;
- TA = 0xAA;
- TA = 0x55;
- WDCON0 |= WDT_CLK_DIV; // Select bit length of WDT counter
- EA = EA_Save_bit;
- set_WDCLR; // Clear WDT counter
- clr_WDTF;
- set_WDTEN; // Enable WDT
- EWDI = 1; // Enable WDT interrupt
- EA = 1; // Enable interrupt
- while(1);
- }
- //-----------------------------------------------------------------------------------------------------------
- void WDT_ISR(void) interrupt 10 // Vector @ 0x53
- {
- clr_WDTF; // Clear WDT flag
- P14 = ~P14; // P1.4 toggle when interrupt
- P21 = ~P21; // P2.1 toggle when interrupt
- }
- //-----------------------------------------------------------------------------------------------------------
|