⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int_timer.c

📁 ti-Chipcon CC2430 zigbee Soc应用开发源码实例。包括rf,powermodes,clockmodes底层驱动源码。有了这些实例,包括误码率测试等。对你更好的理解和应用这颗芯片
💻 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 "lcd.h"

// Prototypes
void int_timer_main(void);
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
*
******************************************************************************/
void main(void){
   uint8 timer3Period;
   uint16 timer1Period;

   initLcd();

   lcdUpdate((char*)"T1:  T2:  T3: ",(char*)"800  400  100");

   //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(1);
}


/******************************************************************************
* @fn  int_timer_T1_IRQ
*
* @brief
*     Interrupt handler for timer T1 interrupts.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
#pragma vector=T1_VECTOR
__interrupt void T1_IRQ(void){
   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
*
******************************************************************************/

#pragma vector=T2_VECTOR
__interrupt void T2_IRQ(void){
   EA = FALSE;
   if(T2CNF & 0x20)
   {
      if(t2)
      {
         t2 = 0;
         lcdUpdateChar(LINE1,8,(char)'*');
         SET_GLED();
      }
      else
      {
         t2 = 1;
         lcdUpdateChar(LINE1,8,(char)' ');
         CLR_GLED();
      }
   }

   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
*
******************************************************************************/
#pragma vector=T3_VECTOR
__interrupt void T3_IRQ(void){
   EA = FALSE;
   if(TIMIF & 0x01){
      //T3 overflow
      t3Val++;
      if(t3Val == 1000)
      {
         t3Val = 0;
         if(t3)
         {
            t3 = 0;
            lcdUpdateChar(LINE1,13,(char)'*');
            SET_YLED();
         }
         else
         {
            t3 = 1;
            lcdUpdateChar(LINE1,13,(char)' ');
            CLR_YLED();
         }
      }
   }
   EA = TRUE;
   TIMIF &= ~0x01;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -