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

📄 power_modes.c

📁 基于cc2430的无限通信实例
💻 C
字号:
/******************************************************************************
Filename:     power_modes.c
Target:       cc2430
Revised:      16/12-2005
Revision:     1.0

Description:
    Demonstrates how to enter and exit the different power modes.

******************************************************************************/

#include <string.h>
#include "RF04EB.h"
#include "app_ex.h"
#include "menu.h"
#include "lcd128_64.h"
#include "hal.h"

extern void (*interrupts[NBR_OF_INTERRUPTS])(void);
void addToSleepTimer(UINT16 sec);
void initPowerModes();
void main(void);




/******************************************************************************
* @fn  power_modes_main
*
* @brief
*     Main function.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void power_modes_main(void){
#else
void main(void){
#endif
    BYTE state = 0;

    TopDisp = 10;
    if(LanguageSel == 1)
    {
        strcpy((char*)MenuItem[0] ,"1:POWERMODE 0  ");
        strcpy((char*)MenuItem[1] ,"2:POWERMODE 1  ");
        strcpy((char*)MenuItem[2] ,"3:POWERMODE 2  ");
        strcpy((char*)MenuItem[3] ,"4:POWERMODE 3  ");
    }
    else
    {
        strcpy((char*)MenuItem[0] ,"1:ģʽ    0    ");
        strcpy((char*)MenuItem[1] ,"2:ģʽ    1    ");
        strcpy((char*)MenuItem[2] ,"3:ģʽ    2    ");
        strcpy((char*)MenuItem[3] ,"4:ģʽ    3    ");
    }

    FirstItem = 0;
    NowItem = 0;
    initPowerModes();
    while (TRUE)
    {
        state = DrawMenu(MenuItem , 4);

        ClearScreen();
        Rectangle(2 , 2 , 108 , 5);
        Print(0,15,"<POWER MODE>",1);
        switch(state)
	{
		case 0:
		{
                    if(LanguageSel == 1)
                    {
                        Print(3,10, "POWERMODE 0",1);
                    }
                    else
                    {
                        Print(3,32,"ģʽ 0",1);
                    }
                    Print6(7,20,"<WAIT 10 SEC>",1);
		    addToSleepTimer(5);
                    INT_GLOBAL_ENABLE(TRUE);
                    INT_ENABLE(INUM_ST, INT_ON);
                    SET_POWER_MODE(0);
		}break;
		case 1:
		{

                    if(LanguageSel == 1)
                    {
                        Print(3,10, "POWERMODE 1",1);
                    }
                    else
                    {
                        Print(3,32, "ģʽ 1",1);
                    }
                    Print6(7,20,"<WAIT 10 SEC>",1);
	            addToSleepTimer(5);
                    INT_GLOBAL_ENABLE(TRUE);
                    INT_ENABLE(INUM_ST, INT_ON);
                    SET_POWER_MODE(1);
		}break;
                case 2:
		{

                    if(LanguageSel == 1)
                    {
                        Print(3,10, "POWERMODE 2",1);
                    }
                    else
                    {
                        Print(3,32, "ģʽ 2",1);
                    }
                    Print6(7,20,"<WAIT 10 SEC>",1);
		    addToSleepTimer(5);
                    INT_GLOBAL_ENABLE(TRUE);
                    INT_ENABLE(INUM_ST, INT_ON);
                    SET_POWER_MODE(2);
		}break;
                case 3:
		{
                    if(LanguageSel == 1)
                    {
                        Print(3,10, "POWERMODE 3",1);
                    }
                    else
                    {
                        Print(3,32, "ģʽ 3",1);
                    }
                    Print6(7,8,"<CANCEL TO WAKE>",1);
		    INT_GLOBAL_ENABLE(TRUE);
                    INT_ENABLE(INUM_ST, INT_OFF);
                    ADC_DISABLE_CHANNEL(1);
                    /*P0DIR &= ~0x02;
                    P0IFG &= ~0x02; // clear interrupt flag P0_1
                    PICTL |= 0x09;  // enable interrupt P0, port 0 to 3*/

                    P0DIR &= ~0x04;
                    P0IFG &= ~0x04; // clear interrupt flag P0_1
                    PICTL |= 0x11;  // enable interrupt P0, port 4 to 7

                    INT_SETFLAG(INUM_P0INT, INT_CLR);
                    INT_ENABLE(INUM_P0INT, INT_ON);
                    SET_MAIN_CLOCK_SOURCE(RC);
                    while (!HIGH_FREQUENCY_RC_OSC_STABLE);
                    SET_POWER_MODE(3);
                    INT_ENABLE(INUM_P0INT, INT_OFF);
                    while(ScanKey() != 0xff);
                    halWait(5);
		}break;
		case 0xff:
		{

		    return;
                }
        default:
            break;
	}
    }
}


/******************************************************************************
* @fn  addToSleepTimer
*
* @brief
*     Function for updating sleep timer.
*
* Parameters:
*
* @param  UINT16 sec
*         Time (in seconds) to add to sleep timer
*
* @return void
*
******************************************************************************/
void addToSleepTimer(UINT16 sec)
{
   UINT32 sleepTimer = 0;

   sleepTimer |= ST0;
   sleepTimer |= (UINT32)ST1 <<  8;
   sleepTimer |= (UINT32)ST2 << 16;

   sleepTimer += ((UINT32)sec * (UINT32)32768);

   ST2 = (UINT8)(sleepTimer >> 16);
   ST1 = (UINT8)(sleepTimer >> 8);
   ST0 = (UINT8) sleepTimer;
}


/******************************************************************************
* @fn  powermodes_P0_IRQ
*
* @brief
*     Interrupt handler for P0.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void powermodes_P0_IRQ(void){
#else
#pragma vector=P0INT_VECTOR
__interrupt void powermodes_P0_IRQ(void){
#endif
   // waiting until the button is released...
   while(!P0_4);
   //halWait(0x50);

   P0IFG &= ~0x10; // clear interrupt flag P0_1
   INT_SETFLAG(INUM_P0INT, INT_CLR);
}


/******************************************************************************
* @fn  powermodes_ST_IRQ
*
* @brief
*     Interrupt handler for Sleep Timer.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void powermodes_ST_IRQ(void){
#else
#pragma vector=ST_VECTOR
__interrupt void powermodes_ST_IRQ(void){
#endif
   INT_SETFLAG(INUM_ST, INT_CLR);
}

/******************************************************************************
* @fn  initPowerModes
*
* @brief
*     Initializes components used for the power modes application example.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void initPowerModes(void)
{

   INIT_GLED();
   INIT_YLED();

   INIT_BUTTON();
   INIT_JOYSTICK_PUSH();
   interrupts[INUM_P0INT] = powermodes_P0_IRQ;
   interrupts[INUM_ST] = powermodes_ST_IRQ;
}



⌨️ 快捷键说明

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