/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
// Nuvoton Technology Corp.
// E-mail: MicroC-8bit@nuvoton.com
//***********************************************************************************************************
// Application: Power Down Wake up
// External interrupt 0 Wake up => P1.3 input low(falling edge).
// External interrupt 1 Wake up => P1.4 input low(falling edge).
// Keyboard interrupt Wake up => P0 input low(falling edge)
// Brown out interrupt Wake up => Vdd < 3.8V
// Watch dog interrupt Wake up => Watch dog timer time out
// ADC interrupt Wake up => ADC conversion finish
//
// Output : UART show result on hyper-terminal
// P1.7 toggle when MCU wake up every once
// P1.4 flash when power down pass
// P2.1 flash when power down pass
//***********************************************************************************************************
//------------------------- <<< Use Configuration Wizard in Context Menu >>> --------------------------------
// <h> Power down wake up source
// <o0.0> External interrupt0
// <0=> Disable
// <1=> Enable
// <o1.0> External interrupt1
// <0=> Disable
// <1=> Enable
// <o2.0> Key board interrupt
// <0=> Disable
// <1=> Enable
// <o3.0> Brown out detect interrupt
// <0=> Disable
// <1=> Enable
// <o4.0> Watch dog timer interrupt
// <0=> Disable
// <1=> Enable
// <o5.0> ADC interrupt
// <0=> Disable
// <1=> Enable
// </h>
// <h> KBI Enable
// <q6.0> KBI.0
// <q6.1> KBI.1
// <q6.2> KBI.2
// <q6.3> KBI.3
// <q6.4> KBI.4
// <q6.5> KBI.5
// <q6.6> KBI.6
// <q6.7> KBI.7
// </h>
//<o7.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
//
// <o8.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 EXT_INT0_EN 1
#define EXT_INT1_EN 1
#define KBI_INT_EN 1
#define BOD_INT_EN 1
#define WDT_INT_EN 1
#define ADC_INT_EN 1
#define KBI_Enable 0xFF
#define WDT_CLK_DIV 0x07
#define Uart_Port_Sel 0x00
#include <stdio.h>
#include "N79E715.h"
#include "Typedef.h"
#include "Define.h"
#include "Common.h"
#include "Delay.h"
#include "ISR.h"
#include "wdt.h"
#include "Version.h"
UINT16 i;
bit EA_Save_bit;
//-----------------------------------------------------------------------------------------------------------
void main()
{
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
printf ("\n*===================================================================");
printf ("\n* Name: N79E715 Series PowerDown Wake-up Sample Code.");
printf ("\n*===================================================================");
printf ("\nPower Down Wake up Demo Start.\n");
P0 = 0x00;
for(i = 0; i<60000; i++);
P0 = 0xFF;
P17 = 0;
EA = 1;
//********************** External interrupt0 ************************
#if EXT_INT0_EN == 1
printf ("\nDemo INT0 Wake Up Function...");
clr_IE0; // Clear external interrupt0 flag first
EX0 = 1; // Enable External interrupt0
PCON |= SET_BIT1; // Enter power down mode
printf ("\nMCU Wake Up...");
P17 = ~P17;
#endif
//********************** External interrupt1 ************************
#if EXT_INT1_EN == 1
printf ("\nDemo INT1 Wake Up Function...");
clr_IE1; // Clear external interrupt1 first
EX1 = 1; // Enable external interrupt1
PCON |= SET_BIT1; // Enter power down mode
printf ("\nMCU Wake Up...");
P17 = ~P17;
#endif
//********************** Keyboard interrupt **************************
#if KBI_INT_EN == 1
printf ("\nDemo KBI Wake Up Function...");
clr_KBIF0; // Clear keyboard interrupt flag first
KBIE = KBI_Enable; // Enable P1 that cause keyboard
EKB = 1; // Enable key board interrupt
PCON |= SET_BIT1; // Enter power down mode
printf ("\nMCU Wake Up...");
P17 = ~P17;
#endif
//********************** Brown out detect ***************************
#if BOD_INT_EN == 1
printf ("\nDemo Brown-Out Wake Up Function...");
TA = 0xAA;
TA = 0x55;
PMCR = 0xC0;
EBO = 1; // Enable brown out detect
PCON |= SET_BIT1;
printf ("\nMCU Wake Up...");
P17 = ~P17;
#endif
//********************** Watch dog timer ****************************
#if WDT_INT_EN == 1
printf ("\nDemo Watch Dog Wake Up Function...");
TA = 0xAA;
TA = 0x55;
WDCON0 |= WDT_CLK_DIV; // Select bit length of WDT counter
TA = 0xAA;
TA = 0x55;
WDCON0 |= SET_BIT4;
clr_WDTF; // Clear WDT flag
EWDI = 1; // Enable WDT interrupt
set_WDCLR; // Clear WDT counter
set_WDTEN; // Enable WDT
PCON |= SET_BIT1; // Enter power down mode
printf ("\nMCU Wake Up...");
P17 = ~P17;
#endif
//********************** ADC interrupt ******************************
#if ADC_INT_EN == 1
printf ("\nDemo ADC Wake Up Function...");
clr_ADCI; // Clear ADC flag first
ADCCON1 |= 0x82; // ADC clock is RC/2 clock and enable ADC
EADC = 1; // Enable ADC interrupt
ADCS = 1; // ADC run
PCON |= SET_BIT1; // Enter power down mode
printf ("\nMCU Wake Up...");
P17 = ~P17;
#endif
printf ("\nPower Down Wake Up Test OK!");
P17 = 1;
while(1)
{
P14 = 1;
P21 = 1;
Delay1ms(500);
P14 = 0;
P21 = 0;
Delay1ms(500);
}
}
//-----------------------------------------------------------------------------------------------------------
void INT0_ISR(void) interrupt 0 // Vector @ 0x03
{
clr_IE0;
EX0 = 0;
}
//-----------------------------------------------------------------------------------------------------------
void INT1_ISR(void) interrupt 2 // Vector @ 0x13
{
clr_IE1;
EX1 = 0;
}
//-----------------------------------------------------------------------------------------------------------
void KBI_ISR(void) interrupt 7 // Vector @ 0x3B
{
clr_KBIF0;
EKB = 0;
}
//-----------------------------------------------------------------------------------------------------------
void BOD_ISR(void) interrupt 8 // Vector @ 0x43
{
clr_BOF;
EBO = 0;
}
//-----------------------------------------------------------------------------------------------------------
void WDT_ISR(void) interrupt 10 // Vector @ 0x53
{
clr_WDTF;
clr_WDTEN;
EWDI = 0;
}
//-----------------------------------------------------------------------------------------------------------
void ADC_ISR(void) interrupt 11 // Vector @ 0x5B
{
clr_ADCI;
EADC = 0;
}
//-----------------------------------------------------------------------------------------------------------
|