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

📄 timer01.c

📁 基于cc1010的设计实例
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                    CHIPCON CC1010 EXAMPLE PROGRAM            *
 *      ***   + +   ***          Simple timer demonstration program          *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 * This program demonstrates the use of timers.                              *
 *                                                                           *
 * The program uses timer 0 to generate interrupts at regular intervals      *
 * (60 msecs). The interrupt service routine resets the timer and toggles    *
 * the red and the yellow LEDs                                               *
 *****************************************************************************
 * Author:              TEL, JOL                                             *
 *****************************************************************************
 * Revision history:                                                         *
 * 1.0  2002/08/29      First Public Release                                 *
 *                                                                           *
 * $Log: timer01.c,v $
 * Revision 1.3  2003/08/18 12:24:44  tos
 * Synchronisation with library update (reentry issue).
 *
 * Revision 1.2  2002/11/19 15:43:39  kht
 * Added startup macros
 *
 * Revision 1.1  2002/10/14 11:15:15  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/reg1010.h>
#include <chipcon/cc1010eb.h>
#include <chipcon/hal.h>


ulong timeout;
word  tCounter;


//----------------------------------------------------------------------------
//  MAIN PROGRAM
//----------------------------------------------------------------------------
void main() {

    // Disable watchdog timer
    WDT_ENABLE(FALSE); 

    // Set optimum settings for speed and low power consumption
    MEM_NO_WAIT_STATES();
    FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);

    // Initialize LEDS
    RLED_OE(TRUE); RLED = LED_OFF;
    YLED_OE(TRUE); YLED = LED_ON;

    // Configure timer 0 to generate an interrupt after 30 msec.
    timeout = 30000; // usec
    halConfigTimer01(TIMER0 | TIMER01_INT_TIMER, timeout, CC1010EB_CLKFREQ, &tCounter);
    INT_ENABLE(INUM_TIMER0, INT_ON);
    TIMER0_RUN(TRUE);
    INT_GLOBAL_ENABLE(TRUE);


    // Loop forever
    while (TRUE) {} 

} // main



//----------------------------------------------------------------------------
//  Timer 0 interrupt service routine:
//----------------------------------------------------------------------------
void TIMER0_ISR() interrupt INUM_TIMER0 {

    // Reset the timer to generate another interrupt
    INT_SETFLAG (INUM_TIMER0, INT_CLR);
    ISR_TIMER0_ADJUST(tCounter);
         
    // Toggle leds
    RLED = ~RLED;   
    YLED = ~YLED;

} // TIMER0_ISR

⌨️ 快捷键说明

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