/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
// Website: http://www.nuvoton.com
// E-Mail : MicroC-8bit@nuvoton.com
//***********************************************************************************************************
#include "ML51.h"
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Timer delay interrupt demo
* @param None
* [url=home.php?mod=space&uid=266161]@return[/url] None
* [url=home.php?mod=space&uid=1543424]@Details[/url] None
*/
/************************************************************************************************************
* TIMER 0 interrupt subroutine
************************************************************************************************************/
void Timer0_ISR(void) interrupt 1 // Vector [url=home.php?mod=space&uid=72445]@[/url] 0x0B
{
clr_TCON_TF0;
P31 ^= 1;
}
/************************************************************************************************************
* TIMER 1 interrupt subroutine
************************************************************************************************************/
void Timer1_ISR(void) interrupt 3 // Vector @ 0x1B
{
clr_TCON_TF1;
P31 ^= 1;
}
/************************************************************************************************************
* TIMER 2 interrupt subroutine
************************************************************************************************************/
void Timer2_ISR(void) interrupt 5 // Vector @ 0x2B
{
clr_T2CON_TF2;
P31 ^= 1;
}
/************************************************************************************************************
* TIMER 3 interrupt subroutine
************************************************************************************************************/
void Timer3_ISR(void) interrupt 16 // Vector @ 0x83
{
clr_T3CON_TF3;
P31 ^= 1;
}
void main (void)
{
MFP_P31_GPIO;
P31_PUSHPULL_MODE;
/* Include timer.c */
/* Timer0 base is HIRC 24MHz(24000000), delay 200ms = (200, 1000) */
Timer0_Delay(24000000,200,1000);
set_TCON_TR0;
/* Timer1 base is HIRC 24MHz(24000000), delay 1.8ms = (6, 300) */
Timer1_Delay(24000000,6,300);
set_TCON_TR1;
/* Timer1 base is HIRC 24MHz(24000000), devieder 512, delay 1 s = (2, 500000) */
Timer2_Delay(24000000,512,2,500000);
set_T2CON_TR2;
/* Timer1 base is HIRC 24MHz(24000000), devieder 128, delay300 ms = (1, 300000) */
Timer3_Delay(24000000,128,1,300000);
set_T3CON_TR3;
Timer_Interrupt_Enable(TIMER0);
Timer_Interrupt_Enable(TIMER1);
Timer_Interrupt_Enable(TIMER2);
Timer_Interrupt_Enable(TIMER3);
ENABLE_GLOBAL_INTERRUPT;
while(1);
}
|