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

📄 app_ex_main.c

📁 Chipcon CC2431 EB TestProgram
💻 C
字号:
/******************************************************************************
*                                                                             *
*        **********                                                           *
*       ************                                                          *
*      ***        ***                                                         *
*     ***    ++    ***                                                        *
*     ***   +  +   ***                      CHIPCON                           *
*     ***   +                                                                 *
*     ***   +  +   ***                                                        *
*     ***    ++    ***                                                        *
*      ***        ***                                                         *
*       ************                                                          *
*        **********                                                           *
*                                                                             *
*******************************************************************************

Filename:     app_ex_main.c
Target:       cc2430
Author:       KJA/ EFU
Revised:      16/12-2005
Revision:     1.0

Description:
    Application example, SmartRF04EB.

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

#include "app_ex.h"


BOOL checkForInput(void);


APPLICATION apps[NBR_OF_APPS];
UINT8 activeApp;


/******************************************************************************
* @fn  initAppEx
*
* @brief
*      Initializes the application example.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void initAppEx(void)
{
   UINT8 i, j;

   SET_MAIN_CLOCK_SOURCE(CRYSTAL);

   initLcd();

   // init all interrupt functions to dummy, just a return statement
   for(i = 0; i < NBR_OF_APPS; i++){
      for(j = 0; j < NBR_OF_INTERRUPTS; j++){
         apps[i].interrupts[j] = dummyInterrupt;
      }
   }

   //Turning on radio power.
   RFPWR = 0x04;
   while(RFPWR & 0x10);

   adc_init(&apps[ADC_CONV]);
   adc_series_init(&apps[ADC_SERIES]);
   // temp_sensor_init(&apps[TEMP_SENSOR]);
   stop_watch_init(&apps[STOP_WATCH]);
   uart_init(&apps[UART]);
   clockmodes_init(&apps[CLOCKMODES]);
   rf_test_init(&apps[RF_TEST]);
   //rf232_init(&apps[RF232]);
   random_init(&apps[RANDOM]);
   aes_init(&apps[AES]);
   flash_init(&apps[FLASH]);
   dma_init(&apps[DMA]);
   power_init(&apps[POWER]);
   timer_int_init(&apps[TIMER_INT]);
   external_int_init(&apps[EXTERNAL_INT]);

   activeApp = RF_TEST;

}


/******************************************************************************
* @fn  main
*
* @brief
*      Main function of application example.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void main(void)
{
   initAppEx();

   showLogo();

   while(getJoystickDirection() == CENTRED);
   updateMenu();
   while(getJoystickDirection() != CENTRED);

   for(;;){
      if(checkForInput()){
         updateMenu();
      }
   }
}


/******************************************************************************
* @fn  main
*
* @brief
*      This function updates the menu on the LCD-display.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void updateMenu(void)
{
   char up = ARROW_UP;
   char down = ARROW_DOWN;

   lcdUpdate(apps[activeApp].menuText, apps[activeApp].description);

   if (activeApp == 0){
      up = ' ';
   }
   else if (activeApp == NBR_OF_APPS - 1){
      down = ' ';
   }
   lcdUpdateChar(LINE1, LINE_SIZE - 1, up);
   lcdUpdateChar(LINE2, LINE_SIZE - 1, down);
}


/******************************************************************************
* @fn  checkForInput
*
* @brief
*      Polls joystick for current position.
*
* Parameters:
*
* @param  void
*
* @return BOOL
*         TRUE    Input from joystick, menu update needed.
*         FALSE   No input.
*
******************************************************************************/
BOOL checkForInput(void)
{
   static JOYSTICK_DIRECTION js;
   JOYSTICK_DIRECTION js_t;

   js_t = getJoystickDirection();

   if(js_t != js){
      js = js_t;

      switch (js){
      case UP:
         if (activeApp > 0){
            activeApp--;
            return TRUE;
         }
         else{
            return FALSE;
         }
      case DOWN:
         if (activeApp < NBR_OF_APPS - 1){
            activeApp++;
            return TRUE;
         }
         else{
            return FALSE;
         }
      case LEFT:
         return FALSE;
      case RIGHT:
         startApplication();
         return TRUE;
      case CENTRED:
         return FALSE;
      }
   }
   return FALSE;
}


/******************************************************************************
* @fn  startApplication
*
* @brief
*     Start the selected application.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void startApplication(void)
{
   DISABLE_ALL_INTERRUPTS();
   SET_MAIN_CLOCK_SOURCE(CRYSTAL);

   apps[activeApp].main_func();

   CLR_GLED();
   CLR_YLED();

   DISABLE_ALL_INTERRUPTS();
}


/******************************************************************************
* @fn  stopApplication
*
* @brief
*     Check for stop application command, Joystick direction left.
*
* Parameters:
*
* @param  void
*
* @return BOOL
*         TRUE    Terminate current application
*         FALSE   No action
*
******************************************************************************/
BOOL stopApplication(void)
{
   return (getJoystickDirection() == LEFT);
}


/******************************************************************************
* @fn  haltApplication
*
* @brief
*     Halts until user stops application.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void haltApplication(void)
{
   while(!stopApplication());
}


/******************************************************************************
* @fn  haltApplicationWithLED
*
* @brief
*     Halts until user stops application, toggle LEDs
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void haltApplicationWithLED(void)
{
   BOOL direction = 0;
   BYTE led_values = 0x01;

   INIT_YLED();

   while(!stopApplication()){
      YLED = !!((led_values & 0x01));

      if(direction == 0)
         (led_values < 0x08) ? (led_values <<= 1):(led_values = 0x08, direction = 1);
      else
         (led_values > 0x01) ? (led_values >>= 1):(led_values = 0x01, direction = 0);

      halWait(40);
   }
}



⌨️ 快捷键说明

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