📄 int_timer.c
字号:
/******************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** ++ *** *
* *** + + *** CHIPCON *
* *** + *
* *** + + *** *
* *** ++ *** *
* *** *** *
* ************ *
* ********** *
* *
*******************************************************************************
Filename: int_timer.c
Target: cc2430
Author: kja
Revised: 16/12-2005
Revision: 1.0
Description:
Timer 1,2 and 3 are configured to run and generate interrupts. Each timer
is associated with an asterisk on the LCD.
******************************************************************************/
#include "app_ex.h"
// Prototypes
void int_timer_main(void);
void int_timer_init(APPLICATION *a);
void int_timer_T1_IRQ(void);
void int_timer_T2_IRQ(void);
void int_timer_T3_IRQ(void);
void int_timer_T4_IRQ(void);
void timer_int_main(void);
_Bool t1 = 0;
_Bool t2 = 0;
_Bool t3 = 0;
UINT16 t1Val = 0;
UINT16 t3Val = 0;
/******************************************************************************
* @fn timer_int_main
*
* @brief
* Main function.
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void timer_int_main(void){
#else
void main(void){
#endif
UINT8 timer3Period;
UINT16 timer1Period;
initLcd();
lcdUpdate((char*)"T1: T2: T3: ",(char*)"(LEFT to exit)");
//Init I/O ports for LEDs and turn light off
INIT_GLED();
INIT_YLED();
YLED = LED_OFF;
SET_MAIN_CLOCK_SOURCE(CRYSTAL);
// Enabling overflow interrupt from timer 1
TIMER1_INIT();
timer1Period = halSetTimer1Period(800);
if(timer1Period != 0)
{
TIMER1_ENABLE_OVERFLOW_INT(TRUE);
INT_ENABLE(INUM_T1, INT_ON);
TIMER1_RUN(TRUE);
}
// Enabling compare interrupt from timer 2
TIMER2_INIT();
halSetTimer2Period(TIMER2_NORMAL_TIMER,400);
TIMER2_ENABLE_OVERFLOW_COMP_INT(TRUE);
INT_ENABLE(INUM_T2, INT_ON);
T2CNF = 0x04;
TIMER2_RUN(TRUE);
// Setting up Timer 3 and enabling overflow interrupt.
TIMER34_INIT(3);
timer3Period = halSetTimer34Period(3, 100);
if(timer3Period != 0)
{
TIMER34_ENABLE_OVERFLOW_INT(3,INT_ON);
INT_ENABLE(INUM_T3, INT_ON);
TIMER3_RUN(TRUE);
}
INT_GLOBAL_ENABLE(TRUE);
// Running until the application is stopped.
while(!stopApplication());
LED1 = LED3 = LED_OFF;
INT_ENABLE(INUM_T1, INT_OFF);
INT_ENABLE(INUM_T2, INT_OFF);
INT_ENABLE(INUM_T3, INT_OFF);
INT_ENABLE(INUM_T4, INT_OFF);
}
/******************************************************************************
* @fn int_timer_T1_IRQ
*
* @brief
* Interrupt handler for timer T1 interrupts.
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void int_timer_T1_IRQ(void){
#else
#pragma vector=T1_VECTOR
__interrupt void T1_IRQ(void){
#endif
EA = FALSE;
if(T1CTL & 0x10){
//T1 overflow
t1Val++;
if(t1Val == 1000)
{
t1Val = 0;
if(t1)
{
t1 = 0;
lcdUpdateChar(LINE1,3,(char)'*');
}
else
{
t1 = 1;
lcdUpdateChar(LINE1,3,(char)' ');
}
}
}
EA = TRUE;
T1CTL &= ~0x10;
}
/******************************************************************************
* @fn int_timer_T2_IRQ
*
* @brief
* Interrupt handler for timer T2 interrupts.
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void int_timer_T2_IRQ(void){
#else
#pragma vector=T2_VECTOR
__interrupt void T2_IRQ(void){
#endif
EA = FALSE;
if(T2CNF & 0x20)
{
if(t2)
{
t2 = 0;
lcdUpdateChar(LINE1,8,(char)'*');
}
else
{
t2 = 1;
lcdUpdateChar(LINE1,8,(char)' ');
}
}
T2OF2 = 0;
T2OF1 = 0;
T2OF0 = 0;
T2CNF &= ~0x20;
EA = TRUE;
}
/******************************************************************************
* @fn int_timer_T3_IRQ
*
* @brief
* Interrupt handler for timer T3 interrupts.
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void int_timer_T3_IRQ(void){
#else
#pragma vector=T3_VECTOR
__interrupt void T3_IRQ(void){
#endif
EA = FALSE;
if(TIMIF & 0x01){
//T3 overflow
t3Val++;
if(t3Val == 1000)
{
t3Val = 0;
if(t3)
{
t3 = 0;
lcdUpdateChar(LINE1,13,(char)'*');
}
else
{
t3 = 1;
lcdUpdateChar(LINE1,13,(char)' ');
}
}
}
EA = TRUE;
TIMIF &= ~0x01;
}
/******************************************************************************
* @fn timer_int_init
*
* @brief
* Initializes timer interrupt application example.
*
* Parameters:
*
* @param APPLICATION *a
* Main application
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void timer_int_init(APPLICATION *a){
a->menuText = (char*)"Timer";
a->description = (char*)"Interrupts";
a->main_func = timer_int_main;
a->interrupts[INUM_T1] = int_timer_T1_IRQ;
a->interrupts[INUM_T2] = int_timer_T2_IRQ;
a->interrupts[INUM_T3] = int_timer_T3_IRQ;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -