/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
// Nuvoton Technology Corp.
// E-mail: MicroC-8bit@nuvoton.com
//***********************************************************************************************************
// Application: Use interrupt service routine
// Set individual flag of each interrupt to execute ISR .
//
// Output : P0 show result
// P1.4 flash when all interrupt pass
// P2.1 flash when all interrupt pass
// P0.7 flash when interrupt error
//***********************************************************************************************************
#include <stdio.h>
#include "N79E715.h"
#include "Typedef.h"
#include "Define.h"
#include "Common.h"
#include "Delay.h"
#include "ISR.h"
#include "Version.h"
bit EA_Save_bit;
//-----------------------------------------------------------------------------------------------------------
void Interrupt_Error(void)
{
while(1)
{
P07 = 1;
Delay1ms(500);
P07 = 0;
Delay1ms(500);
}
}
//-----------------------------------------------------------------------------------------------------------
void main(void)
{
uint16_t i;
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* N79E715 Series Interrupt Sample Code.");
printf ("\n*==========================================================================\n");
TR1 = 0; //Stop Timer1 for Interrupt Demo
IE = 0x7F;
EIE = 0xFF;
EA = 1;
//********************** INT0 Test ***********************
P0 = 0xFF;
IT0 = 1;
set_IE0; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x01) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************* Timer0 Test **********************
P0 = 0xFF;
set_TF0; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x02) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************** INT1 Test ***********************
P0 = 0xFF;
IT1 = 1;
set_IE1; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x03) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************* Timer1 Test **********************
P0 = 0xFF;
set_TF1; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x04) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************** UART0 Test **********************
P0 = 0xFF;
set_RI; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x05) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************* Timer2 Test **********************
P0 = 0xFF;
set_TF2; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
/* Check ISR return value */
if(P0 != ~0x06) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************** I2C Test ************************
P0 = 0xFF;
set_SI; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x07) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************** KBI Test ************************
P0 = 0xFF;
set_KBIF0; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x08) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************** BOD Test ************************
P0 = 0xFF;
set_BOF; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x09) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************** SPI Test ************************
P0 = 0xFF;
// Trigger Interrupt
set_SPIF;
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x0A) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//******************* Watch Dog Test *********************
P0 = 0xFF;
set_WDTF; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x0B) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************** ADC Test ************************/
P0 = 0xFF;
set_ADCI; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x0C) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//******************** Capture Test **********************
P0 = 0xFF;
set_CAPF0; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x0D) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
//********************** PWM Test ************************
P0 = 0xFF;
set_BKF; // Trigger Interrupt
PCON |= SET_BIT0; // Enter Idle Mode
if(P0 != ~0x0E) // Check ISR return value
Interrupt_Error();
for(i = 0 ; i < 60000 ; i++); // Delay time
EA = 0; // Disable all interrupt
InitialUART0_Timer1(9600); // 9600 Baud Rate @ 11.0592MHz
printf("\nInterrupt Test OK!");
while(1)
{
P14 = 1;
P21 = 1;
Delay1ms(500);
P14 = 0;
P21 = 0;
Delay1ms(500);
}
}
//-----------------------------------------------------------------------------------------------------------
void INT0_ISR(void) interrupt 0 // Vector @ 0x03
{
P0 = 0xFF-1;
clr_IE0;
}
//-----------------------------------------------------------------------------------------------------------
void Timer0_ISR(void) interrupt 1 // Vector @ 0x0B
{
P0 = 0xFF-2;
clr_TF0;
}
//-----------------------------------------------------------------------------------------------------------
void INT1_ISR(void) interrupt 2 // Vector @ 0x13
{
P0 = 0xFF-3;
clr_IE1;
}
//-----------------------------------------------------------------------------------------------------------
void Timer1_ISR(void) interrupt 3 // Vector @ 0x1B
{
P0 = 0xFF-4;
clr_TF1;
}
//-----------------------------------------------------------------------------------------------------------
void UART0_ISR(void) interrupt 4 // Vector @ 0x23
{
P0 = 0xFF-5;
clr_RI;
}
//-----------------------------------------------------------------------------------------------------------
void Timer2_ISR(void) interrupt 5 // Vector @ 0x2B
{
P0 = 0xFF-6;
clr_TF2;
}
//-----------------------------------------------------------------------------------------------------------
void I2C_ISR(void) interrupt 6 // Vector @ 0x33
{
P0 = 0xFF-7;
clr_SI;
}
//-----------------------------------------------------------------------------------------------------------
void KBI_ISR(void) interrupt 7 // Vector @ 0x3B
{
P0 = 0xFF-8;
clr_KBIF0;
}
//-----------------------------------------------------------------------------------------------------------
void BOD_ISR(void) interrupt 8 // Vector @ 0x43
{
P0 = 0xFF-9;
clr_BOF;
}
//-----------------------------------------------------------------------------------------------------------
void SPI_ISR(void) interrupt 9 // Vector @ 0x4B
{
P0 = 0xFF-10;
clr_SPIF;
}
//-----------------------------------------------------------------------------------------------------------
void WDT_ISR(void) interrupt 10 // Vector @ 0x53
{
P0 = 0xFF-11;
clr_WDTF;
}
//-----------------------------------------------------------------------------------------------------------
void ADC_ISR(void) interrupt 11 // Vector @ 0x5B
{
P0 = 0xFF-12;
clr_ADCI;
}
//-----------------------------------------------------------------------------------------------------------
void Capture_ISR(void) interrupt 12 // Vector @ 0x63
{
P0 = 0xFF-13;
clr_CAPF0;
}
//-----------------------------------------------------------------------------------------------------------
void PWM_Brake_ISR(void) interrupt 14 // Vector @ 0x73
{
P0 = 0xFF-14;
clr_BKF;
}
//-----------------------------------------------------------------------------------------------------------
|