?? xosc_switching.c
字號:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 EXAMPLE PROGRAM *
* *** + + *** XOSC/POWER SWITCHING *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* Demonstrates: *
* - CC1010 XOSC switching (32 kHz <-> 14 MHz). *
* - CC1010 powermode switcing (ACTIVE <-> IDLE) *
* *
*****************************************************************************
* Author: TOS *
*****************************************************************************
* *
* $Log: xosc_switching.c,v $
* Revision 1.2 2004/01/09 16:20:50 tos
* Removed obsolete delay function.
*
* Revision 1.1 2003/12/11 12:52:17 tos
* Initial version in CVS.
*
*
* *
****************************************************************************/
#include <chipcon/hal.h>
#include <chipcon/cc1010eb.h>
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_OE(FALSE);
YLED_OE(FALSE);
GLED_OE(TRUE);
BLED_OE(TRUE);
RLED=YLED=GLED=BLED=LED_OFF;
// Inactivate realtime clock
RTC_RUN(FALSE);
// Switch regularly between low -and high speed XOSC:
while(1) {
/////////////////////////////////////////////////////////////////
////////////////// Switch to low-speed XOSC /////////////////////
/////////////////////////////////////////////////////////////////
// Enable low-speed XOSC
X32_INPUT_SOURCE(X32_USING_CRYSTAL);
X32_ENABLE(TRUE);
// Wait until low-speed XOSC is stable:
// At this point CC1010 is running on high-speed XOSC, so 0.5 sec
// is required to wait for low-speed XOSC stabilization
halWait(250, CC1010EB_CLKFREQ);
halWait(250, CC1010EB_CLKFREQ);
// Switch to low-speed XOSC
MAIN_CLOCK_SET_SOURCE(CLOCK_X32);
// Disable / turn off high-speed oscillator
XOSC_ENABLE(FALSE);
BLED = LED_ON;
GLED = LED_OFF;
// Set all unused ports as input
P0DIR = 0xFF;
P1DIR |= 0xEF;
P2DIR |= 0xDF;
P3DIR = 0xFF;
// Assert all unused ports
P0 = 0xFF;
P1 |= 0xEF;
P2 |= 0xDF;
P3 = 0xFF;
// Power down RF-transceiver
RFMAIN=0xF8;
// Configure realtime clock to support wake-up from IDLE
halConfigRealTimeClock(4);
// Enable realtime clock (implicit: interrupt enable)
RTC_RUN(TRUE);
// Enter IDLE mode
ENTER_IDLE_MODE();
// Comment:
// CC1010 will now be woken up by the RTC interrupt.
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
////////////////// Switch to high-speed XOSC ////////////////////
/////////////////////////////////////////////////////////////////
// Enable high-speed XOSC
XOSC_ENABLE(TRUE);
// Wait until high-speed XOSC is stable:
// At this point CC1010 is running on low-speed XOSC, so only 1 loop
// iteration is required to wait for high-speed XOSC stabilization
// Comment:
// Do not use halWait(...) because it is not intended for low-speed XOSC.
for(i = 1; i > 0; i--);
// Switch to low-speed XOSC
MAIN_CLOCK_SET_SOURCE(CLOCK_XOSC);
// Disable / turn off low-speed oscillator
X32_ENABLE(FALSE);
// Do something intelligent...
GLED = LED_ON;
halWait(200, CC1010EB_CLKFREQ);
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
}
}
// ISR (interrupt service routine) for RTC, priority 11
// The interrupt must be cleared by software
void isr_rtc() interrupt INUM_RTC {
RTC_RUN(FALSE);
INT_SETFLAG(INUM_RTC, INT_CLR);
BLED = LED_OFF;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -