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

📄 clockmodes.c

📁 基于cc1010的设计实例
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                    CHIPCON CC1010 EXAMPLE PROGRAM            *
 *      ***   + +   ***                      CLOCK MODES                     *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 * Demonstrates the CC1010 clock modes. Uses the functions and macros:       *
 * - MAIN_CLOCK_SET_SOURCE, XOSC_ENABLE, X32_ENABLE, X32_INPUT_SOURCE macros *
 * - halWait function                                                        *
 *                                                                           *
 * The program switches between using the high-speed and the 32kHz clock     *
 * oscillators as the main clock source. The red and green LEDs blink with a *
 * frequency of 1Hz depending on the selected clock source.                  *
 *****************************************************************************
 * Author:              ARR                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 * 1.0  2002/08/28      First public release                                 *
 *                                                                           *
 * $Log: clockmodes.c,v $
 * Revision 1.2  2002/11/18 10:19:44  kht
 * Added startup macros
 *
 * Revision 1.1  2002/10/11 14:52:45  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

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

// 32 kHz crystal clock frequency in kHz
#define X32_CLKFREQ 32

int main() {
    
    int i;

    // Disable watchdog timer
    WDT_ENABLE(FALSE);

    // Startup macros for speed and low power consumption
    MEM_NO_WAIT_STATES();
    FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);

    // All I/Os are inputs after reset. Make I/Os connected to LEDs outputs
    RLED=YLED=GLED=BLED=LED_OFF;
    RLED_OE(TRUE); YLED_OE(TRUE); GLED_OE(TRUE); BLED_OE(TRUE);

    // Infinite loop
    while(1) {

        // Switch LEDS off
        YLED=GLED=LED_OFF;

        // Enable 32kHz oscillator, wait 0.5s to stabilize, 
        // then switch clock source, then disable high-speed XOSC
        X32_INPUT_SOURCE(X32_USING_CRYSTAL);
        X32_ENABLE(TRUE);
        halWait(250, CC1010EB_CLKFREQ);
        halWait(250, CC1010EB_CLKFREQ);
        MAIN_CLOCK_SET_SOURCE(CLOCK_X32);
        XOSC_ENABLE(FALSE);

        // Switch the red LED 10 times to verify new clock frequency
        for (i=0; i<10; i++) {
            RLED = LED_ON;
            halWait(250, X32_CLKFREQ);
            halWait(250, X32_CLKFREQ);
            RLED = LED_OFF;
            halWait(250, X32_CLKFREQ);
            halWait(250, X32_CLKFREQ);
        }

        // Enable high speed XOSC, switch clock source, then disable 32kHz XOSC
        XOSC_ENABLE(TRUE);
        MAIN_CLOCK_SET_SOURCE(CLOCK_XOSC);
        X32_ENABLE(FALSE);

        // Switch the green LED 10 times to verify new clock frequency
        for (i=0; i<10; i++) {
            GLED = LED_ON;
            halWait(250, CC1010EB_CLKFREQ);
            halWait(250, CC1010EB_CLKFREQ);
            GLED = LED_OFF;
            halWait(250, CC1010EB_CLKFREQ);
            halWait(250, CC1010EB_CLKFREQ);
        }

    }
}

⌨️ 快捷键说明

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