查看: 5873|回复: 1

关于CC2530在Z-STACK中P0口按键中断的问题,求指教

[复制链接]
  • TA的每日心情
    开心
    2016-12-8 15:01
  • 签到天数: 459 天

    连续签到: 1 天

    [LV.9]以坛为家II

    发表于 2013-12-26 17:10:56 | 显示全部楼层 |阅读模式
    分享到:
    串口0预留,所以P0口还有5个脚全部用来外部中断,外加上P2口一个,共六个。在Z-STACK中HAL层加入代码后,按键产生的事件不能具体识别是哪一个按键按下的。先贴上KEY.C的代码,求大神指导下这部分代码有问题没?

    /**************************************************************************************************
    *                                            CONSTANTS
    **************************************************************************************************/
    #define HAL_KEY_RISING_EDGE   0
    #define HAL_KEY_FALLING_EDGE  1

    #define HAL_KEY_DEBOUNCE_VALUE  135
    #define HAL_KEY_POLLING_VALUE   100

    /* CPU port interrupt (key P0.1 J-STICK P2.0)*/
    #define HAL_KEY_CPU_PORT_0_IF P0IF
    #define HAL_KEY_CPU_PORT_2_IF P2IF
             
    /* SW_7 is at P0.4 */
    #define HAL_KEY_SW_7_PORT   P0
    #define HAL_KEY_SW_7_BIT    BV(1)
    #define HAL_KEY_SW_7_SEL    P0SEL
    #define HAL_KEY_SW_7_DIR    P0DIR
    /* edge interrupt */
    #define HAL_KEY_SW_7_EDGEBIT  BV(0)
    #define  HAL_KEY_SW_7_EDGE   HAL_KEY_RISING_EDGE
    /* SW_5 interrupts */
    #define HAL_KEY_SW_7_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_7_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_7_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_7_ICTLBIT  BV(1) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_7_PXIFG    P0IFG /* Interrupt flag at source */

    /* SW_6 is at P0.0 */
    #define HAL_KEY_SW_6_PORT   P0
    #define HAL_KEY_SW_6_BIT    BV(0)
    #define HAL_KEY_SW_6_SEL    P0SEL
    #define HAL_KEY_SW_6_DIR    P0DIR
    /* edge interrupt */
    #define HAL_KEY_SW_6_EDGEBIT  BV(0)
    #define HAL_KEY_SW_6_EDGE    HAL_KEY_RISING_EDGE    //  HAL_KEY_FALLING_EDGE   边沿触发改为上升沿触发
    /* SW_6 interrupts */
    #define HAL_KEY_SW_6_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_6_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_6_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_6_ICTLBIT  BV(0) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_6_PXIFG    P0IFG /* Interrupt flag at source */

    /* SW_5 is at P0.4 */
    #define HAL_KEY_SW_5_PORT   P0
    #define HAL_KEY_SW_5_BIT    BV(4)
    #define HAL_KEY_SW_5_SEL    P0SEL
    #define HAL_KEY_SW_5_DIR    P0DIR
    /* edge interrupt */
    #define HAL_KEY_SW_5_EDGEBIT  BV(0)
    #define  HAL_KEY_SW_5_EDGE   HAL_KEY_RISING_EDGE
    /* SW_5 interrupts */
    #define HAL_KEY_SW_5_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_5_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_5_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_5_ICTLBIT  BV(4) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_5_PXIFG    P0IFG /* Interrupt flag at source */

    /* SW_4 is at P0.5 */
    #define HAL_KEY_SW_4_PORT   P0
    #define HAL_KEY_SW_4_BIT    BV(5)
    #define HAL_KEY_SW_4_SEL    P0SEL
    #define HAL_KEY_SW_4_DIR    P0DIR
    /* edge interrupt */
    #define HAL_KEY_SW_4_EDGEBIT  BV(0)
    #define  HAL_KEY_SW_4_EDGE   HAL_KEY_RISING_EDGE
    /* SW_4 interrupts */
    #define HAL_KEY_SW_4_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_4_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_4_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_4_ICTLBIT  BV(5) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_4_PXIFG    P0IFG /* Interrupt flag at source */

    /* SW_3 is at P0.6 */
    #define HAL_KEY_SW_3_PORT   P0
    #define HAL_KEY_SW_3_BIT    BV(6)
    #define HAL_KEY_SW_3_SEL    P0SEL
    #define HAL_KEY_SW_3_DIR    P0DIR
    /* edge interrupt */
    #define HAL_KEY_SW_3_EDGEBIT  BV(0)
    #define  HAL_KEY_SW_3_EDGE   HAL_KEY_RISING_EDGE
    /* SW_3 interrupts */
    #define HAL_KEY_SW_3_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_3_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_3_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_3_ICTLBIT  BV(6) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_3_PXIFG    P0IFG /* Interrupt flag at source */


    /* SW_2 is at P0.7 */
    #define HAL_KEY_SW_2_PORT   P0
    #define HAL_KEY_SW_2_BIT    BV(7)
    #define HAL_KEY_SW_2_SEL    P0SEL
    #define HAL_KEY_SW_2_DIR    P0DIR
    /* edge interrupt */
    #define HAL_KEY_SW_2_EDGEBIT  BV(0)
    #define  HAL_KEY_SW_2_EDGE    HAL_KEY_RISING_EDGE
    /* SW_2 interrupts */
    #define HAL_KEY_SW_2_IEN      IEN1  /* CPU interrupt mask register */
    #define HAL_KEY_SW_2_IENBIT   BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_2_ICTL     P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_2_ICTLBIT  BV(7) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_2_PXIFG    P0IFG /* Interrupt flag at source */

    /* Joy stick move at P2.0 */
    #define HAL_KEY_JOY_MOVE_PORT   P2
    #define HAL_KEY_JOY_MOVE_BIT    BV(0)
    #define HAL_KEY_JOY_MOVE_SEL    P2SEL
    #define HAL_KEY_JOY_MOVE_DIR    P2DIR

    /* edge interrupt */
    #define HAL_KEY_JOY_MOVE_EDGEBIT  BV(3)
    #define HAL_KEY_JOY_MOVE_EDGE     HAL_KEY_FALLING_EDGE

    /* Joy move interrupts */
    #define HAL_KEY_JOY_MOVE_IEN      IEN2  /* CPU interrupt mask register */
    #define HAL_KEY_JOY_MOVE_IENBIT   BV(1) /* Mask bit for all of Port_2 */
    #define HAL_KEY_JOY_MOVE_ICTL     P2IEN /* Port Interrupt Control register */
    #define HAL_KEY_JOY_MOVE_ICTLBIT  BV(0) /* P2IENL - P2.0<->P2.3 enable/disable bit */
    #define HAL_KEY_JOY_MOVE_PXIFG    P2IFG /* Interrupt flag at source */

    #define HAL_KEY_JOY_CHN   HAL_ADC_CHANNEL_6

    #define HAL_PUSH_BUTTON1()        PUSH1_SBIT   //  
    #define PUSH1_BV          BV(1)
    #define PUSH1_SBIT        P0_1

    #define HAL_PUSH_BUTTON3()        PUSH3_SBIT  //     
    #define PUSH3_BV          BV(0)
    #define PUSH3_SBIT        P0_0

    #define HAL_PUSH_BUTTON4()        PUSH4_SBIT  //
    #define PUSH4_BV          BV(4)
    #define PUSH4_SBIT        P0_4

    #define HAL_PUSH_BUTTON5()        PUSH5_SBIT  //
    #define PUSH5_BV          BV(5)
    #define PUSH5_SBIT        P0_5

    #define HAL_PUSH_BUTTON6()        PUSH6_SBIT  //
    #define PUSH6_BV          BV(6)
    #define PUSH6_SBIT        P0_6

    #define HAL_PUSH_BUTTON7()        PUSH7_SBIT  //
    #define PUSH7_BV          BV(7)
    #define PUSH7_SBIT        P0_7
    /**************************************************************************************************
    *                                            TYPEDEFS
    **************************************************************************************************/


    /**************************************************************************************************
    *                                        GLOBAL VARIABLES
    **************************************************************************************************/
    static uint8 halKeySavedKeys;     /* used to store previous key state in polling mode */
    static halKeyCBack_t pHalKeyProcessFunction;
    static uint8 HalKeyConfigured;
    bool Hal_KeyIntEnable;            /* interrupt enable/disable flag */

    /**************************************************************************************************
    *                                        FUNCTIONS - Local
    **************************************************************************************************/
    void halProcessKeyInterrupt(void);
    uint8 halGetJoyKeyInput(void);



    /**************************************************************************************************
    *                                        FUNCTIONS - API
    **************************************************************************************************/


    /**************************************************************************************************
    * @fn      HalKeyInit
    *
    * @brief   Initilize Key Service
    *
    * @param   none
    *
    * @return  None
    **************************************************************************************************/
    void HalKeyInit( void )
    {
      /* Initialize previous key to 0 */
      halKeySavedKeys = 0;
      HAL_KEY_SW_2_SEL &= ~(HAL_KEY_SW_2_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_2_DIR &= ~(HAL_KEY_SW_2_BIT);    /* Set pin direction to Input */
      HAL_KEY_SW_3_SEL &= ~(HAL_KEY_SW_3_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_3_DIR &= ~(HAL_KEY_SW_3_BIT);    /* Set pin direction to Input */
      HAL_KEY_SW_4_SEL &= ~(HAL_KEY_SW_4_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_4_DIR &= ~(HAL_KEY_SW_4_BIT);    /* Set pin direction to Input */
      HAL_KEY_SW_5_SEL &= ~(HAL_KEY_SW_5_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_5_DIR &= ~(HAL_KEY_SW_5_BIT);    /* Set pin direction to Input */
      HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT);    /* Set pin direction to Input */
      HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_7_DIR &= ~(HAL_KEY_SW_7_BIT);    /* Set pin direction to Input */

    HAL_KEY_JOY_MOVE_SEL &= ~(HAL_KEY_JOY_MOVE_BIT); /* Set pin function to GPIO */
    HAL_KEY_JOY_MOVE_DIR &= ~(HAL_KEY_JOY_MOVE_BIT); /* Set pin direction to Input */


      /* Initialize callback function */
      pHalKeyProcessFunction  = NULL;

      /* Start with key is not configured */
      HalKeyConfigured = FALSE;
    }


    /**************************************************************************************************
    * @fn      HalKeyConfig
    *
    * @brief   Configure the Key serivce
    *
    * @param   interruptEnable - TRUE/FALSE, enable/disable interrupt
    *          cback - pointer to the CallBack function
    *
    * @return  None
    **************************************************************************************************/
    void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
    {
      /* Enable/Disable Interrupt or */
      Hal_KeyIntEnable = interruptEnable;

      /* Register the callback fucntion */
      pHalKeyProcessFunction = cback;

      /* Determine if interrupt is enable or not */
      if (Hal_KeyIntEnable)
      {
        /* Rising/Falling edge configuratinn */
         PICTL &= ~(HAL_KEY_SW_2_EDGEBIT);
         PICTL &= ~(HAL_KEY_SW_3_EDGEBIT);
         PICTL &= ~(HAL_KEY_SW_4_EDGEBIT);
         PICTL &= ~(HAL_KEY_SW_5_EDGEBIT);
         PICTL &= ~(HAL_KEY_SW_6_EDGEBIT);    /* Clear the edge bit */
         PICTL &= ~(HAL_KEY_SW_7_EDGEBIT);    /* Clear the edge bit */
        /* For falling edge, the bit must be set. */
         #if (HAL_KEY_SW_2_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_2_EDGEBIT;
      #endif
         #if (HAL_KEY_SW_3_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_3_EDGEBIT;
      #endif
          #if (HAL_KEY_SW_4_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_4_EDGEBIT;
      #endif
         #if (HAL_KEY_SW_5_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_5_EDGEBIT;
      #endif
      #if (HAL_KEY_SW_6_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_6_EDGEBIT;
      #endif
         #if (HAL_KEY_SW_7_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_7_EDGEBIT;
      #endif

        /* Interrupt configuration:
         * - Enable interrupt generation at the port
         * - Enable CPU interrupt
         * - Clear any pending interrupt
         */
        HAL_KEY_SW_2_ICTL |= HAL_KEY_SW_2_ICTLBIT;
        HAL_KEY_SW_2_IEN |= HAL_KEY_SW_2_IENBIT;
        HAL_KEY_SW_2_PXIFG = ~(HAL_KEY_SW_2_BIT);
       
        HAL_KEY_SW_3_ICTL |= HAL_KEY_SW_3_ICTLBIT;
        HAL_KEY_SW_3_IEN |= HAL_KEY_SW_3_IENBIT;
        HAL_KEY_SW_3_PXIFG = ~(HAL_KEY_SW_3_BIT);
       
        HAL_KEY_SW_4_ICTL |= HAL_KEY_SW_4_ICTLBIT;
        HAL_KEY_SW_4_IEN |= HAL_KEY_SW_4_IENBIT;
        HAL_KEY_SW_4_PXIFG = ~(HAL_KEY_SW_4_BIT);
       
        HAL_KEY_SW_5_ICTL |= HAL_KEY_SW_5_ICTLBIT;
        HAL_KEY_SW_5_IEN |= HAL_KEY_SW_5_IENBIT;
        HAL_KEY_SW_5_PXIFG = ~(HAL_KEY_SW_5_BIT);
       
        HAL_KEY_SW_6_ICTL |= HAL_KEY_SW_6_ICTLBIT;
        HAL_KEY_SW_6_IEN |= HAL_KEY_SW_6_IENBIT;
        HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT);

        HAL_KEY_SW_7_ICTL |= HAL_KEY_SW_7_ICTLBIT;
        HAL_KEY_SW_7_IEN |= HAL_KEY_SW_7_IENBIT;
        HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT);

        /* Rising/Falling edge configuratinn */

        HAL_KEY_JOY_MOVE_ICTL &= ~(HAL_KEY_JOY_MOVE_EDGEBIT);    /* Clear the edge bit */
        /* For falling edge, the bit must be set. */
      #if (HAL_KEY_JOY_MOVE_EDGE == HAL_KEY_FALLING_EDGE)
        HAL_KEY_JOY_MOVE_ICTL |= HAL_KEY_JOY_MOVE_EDGEBIT;
      #endif


        /* Interrupt configuration:
         * - Enable interrupt generation at the port
         * - Enable CPU interrupt
         * - Clear any pending interrupt
         */
        HAL_KEY_JOY_MOVE_ICTL |= HAL_KEY_JOY_MOVE_ICTLBIT;
        HAL_KEY_JOY_MOVE_IEN |= HAL_KEY_JOY_MOVE_IENBIT;
        HAL_KEY_JOY_MOVE_PXIFG = ~(HAL_KEY_JOY_MOVE_BIT);


        /* Do this only after the hal_key is configured - to work with sleep stuff */
        if (HalKeyConfigured == TRUE)
        {
          osal_stop_timerEx( Hal_TaskID, HAL_KEY_EVENT);  /* Cancel polling if active */
        }
      }
      else    /* Interrupts NOT enabled */
      {
        HAL_KEY_SW_2_ICTL &= ~(HAL_KEY_SW_2_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_2_IEN &= ~(HAL_KEY_SW_2_IENBIT);   /* Clear interrupt enable bit */
       
        HAL_KEY_SW_3_ICTL &= ~(HAL_KEY_SW_3_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_3_IEN &= ~(HAL_KEY_SW_3_IENBIT);   /* Clear interrupt enable bit */
       
        HAL_KEY_SW_4_ICTL &= ~(HAL_KEY_SW_4_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_4_IEN &= ~(HAL_KEY_SW_4_IENBIT);   /* Clear interrupt enable bit */
       
        HAL_KEY_SW_5_ICTL &= ~(HAL_KEY_SW_5_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_5_IEN &= ~(HAL_KEY_SW_5_IENBIT);   /* Clear interrupt enable bit */
       
        HAL_KEY_SW_6_ICTL &= ~(HAL_KEY_SW_6_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_6_IEN &= ~(HAL_KEY_SW_6_IENBIT);   /* Clear interrupt enable bit */
       
        HAL_KEY_SW_7_ICTL &= ~(HAL_KEY_SW_7_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_7_IEN &= ~(HAL_KEY_SW_7_IENBIT);   /* Clear interrupt enable bit */

        osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_POLLING_VALUE);    /* Kick off polling */
      }
      /* Key now is configured */
      HalKeyConfigured = TRUE;
    }


    /**************************************************************************************************
    * @fn      HalKeyRead
    *
    * @brief   Read the current value of a key
    *
    * @param   None
    *
    * @return  keys - current keys status
    **************************************************************************************************/
    uint8 HalKeyRead ( void )
    {
      uint8 keys = 0;
      if (!HAL_PUSH_BUTTON1())
      {
        keys |= HAL_KEY_SW_7;
      }
      if (!HAL_PUSH_BUTTON3())
      {
        keys |= HAL_KEY_SW_6;
      }
      if (!HAL_PUSH_BUTTON4())
      {
        keys |= HAL_KEY_SW_5;
      }
      if (!HAL_PUSH_BUTTON5())
      {
        keys |= HAL_KEY_SW_4;
      }
      if (!HAL_PUSH_BUTTON6())
      {
        keys |= HAL_KEY_SW_3;
      }
      if (!HAL_PUSH_BUTTON7())
      {
        keys |= HAL_KEY_SW_2;
      }
      if ((HAL_KEY_JOY_MOVE_PORT & HAL_KEY_JOY_MOVE_BIT))  /* Key is active low */
      {
        keys |= halGetJoyKeyInput();
      }

      return keys;
    }


    /**************************************************************************************************
    * @fn      HalKeyPoll
    *
    * @brief   Called by hal_driver to poll the keys
    *
    * @param   None
    *
    * @return  None
    **************************************************************************************************/
    void HalKeyPoll (void)
    {
      uint8 keys = 0;

      if ((HAL_KEY_JOY_MOVE_PORT & HAL_KEY_JOY_MOVE_BIT))  /* Key is active HIGH */
      {
        keys = halGetJoyKeyInput();
      }

      /* If interrupts are not enabled, previous key status and current key status
       * are compared to find out if a key has changed status.
       */
      if (!Hal_KeyIntEnable)
      {
        if (keys == halKeySavedKeys)
        {
          /* Exit - since no keys have changed */
          return;
        }
        /* Store the current keys for comparation next time */
        halKeySavedKeys = keys;
      }
      else
      {
        /* Key interrupt handled here */
      }

      if (!HAL_PUSH_BUTTON1())
      {
        keys |= HAL_KEY_SW_7;
      }
      if (!HAL_PUSH_BUTTON3())
      {
        keys |= HAL_KEY_SW_6;
      }
      if (!HAL_PUSH_BUTTON4())
      {
        keys |= HAL_KEY_SW_5;
      }
        if (!HAL_PUSH_BUTTON5())
      {
        keys |= HAL_KEY_SW_4;
      }
       if (!HAL_PUSH_BUTTON6())
      {
        keys |= HAL_KEY_SW_3;
      }
        if (!HAL_PUSH_BUTTON7())
      {
        keys |= HAL_KEY_SW_2;
      }
      
      /* Invoke Callback if new keys were depressed */
      if (keys && (pHalKeyProcessFunction))
      {
        (pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL);
      }
    }

    /**************************************************************************************************
    * @fn      halGetJoyKeyInput
    *
    * @brief   Map the ADC value to its corresponding key.
    *
    * @param   None
    *
    * @return  keys - current joy key status
    **************************************************************************************************/
    uint8 halGetJoyKeyInput(void)
    {
      /* The joystick control is encoded as an analog voltage.
       * Read the JOY_LEVEL analog value and map it to joy movement.
       */
      uint8 adc;
      uint8 ksave0 = 0;
      uint8 ksave1;

      /* Keep on reading the ADC until two consecutive key decisions are the same. */
      do
      {
        ksave1 = ksave0;    /* save previouse key reading */

        adc = HalAdcRead (HAL_KEY_JOY_CHN, HAL_ADC_RESOLUTION_8);

        if ((adc >= 2) && (adc <= 38))
        {
           ksave0 |= HAL_KEY_UP;
        }
        else if ((adc >= 74) && (adc <= 88))
        {
          ksave0 |= HAL_KEY_RIGHT;
        }
        else if ((adc >= 60) && (adc <= 73))
        {
          ksave0 |= HAL_KEY_LEFT;
        }
        else if ((adc >= 39) && (adc <= 59))
        {
          ksave0 |= HAL_KEY_DOWN;
        }
        else if ((adc >= 89) && (adc <= 100))
        {
          ksave0 |= HAL_KEY_CENTER;
        }
      } while (ksave0 != ksave1);

      return ksave0;
    }

    /**************************************************************************************************
    * @fn      halProcessKeyInterrupt
    *
    * @brief   Checks to see if it's a valid key interrupt, saves interrupt driven key states for
    *          processing by HalKeyRead(), and debounces keys by scheduling HalKeyRead() 25ms later.
    *
    * @param
    *
    * @return
    **************************************************************************************************/
    void halProcessKeyInterrupt (void)
    {
      bool valid=FALSE;
      if (HAL_KEY_SW_2_PXIFG & HAL_KEY_SW_2_BIT)  /* Interrupt Flag has been set */
      {
        HAL_KEY_SW_2_PXIFG = ~(HAL_KEY_SW_2_BIT); /* Clear Interrupt Flag */
        valid = TRUE;
      }
      if (HAL_KEY_SW_3_PXIFG & HAL_KEY_SW_3_BIT)  /* Interrupt Flag has been set */
      {
        HAL_KEY_SW_3_PXIFG = ~(HAL_KEY_SW_3_BIT); /* Clear Interrupt Flag */
        valid = TRUE;
      }
      if (HAL_KEY_SW_4_PXIFG & HAL_KEY_SW_4_BIT)  /* Interrupt Flag has been set */
      {
        HAL_KEY_SW_4_PXIFG = ~(HAL_KEY_SW_4_BIT); /* Clear Interrupt Flag */
        valid = TRUE;
      }
    if (HAL_KEY_SW_5_PXIFG & HAL_KEY_SW_5_BIT)  /* Interrupt Flag has been set */
      {
        HAL_KEY_SW_5_PXIFG = ~(HAL_KEY_SW_5_BIT); /* Clear Interrupt Flag */
        valid = TRUE;
      }
      if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT)  /* Interrupt Flag has been set */
      {
        HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT); /* Clear Interrupt Flag */
        valid = TRUE;
      }
    if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)  /* Interrupt Flag has been set */
      {
       HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT); /* Clear Interrupt Flag */
       valid = TRUE;
      }

      if (HAL_KEY_JOY_MOVE_PXIFG & HAL_KEY_JOY_MOVE_BIT)  /* Interrupt Flag has been set */
      {
        HAL_KEY_JOY_MOVE_PXIFG = ~(HAL_KEY_JOY_MOVE_BIT); /* Clear Interrupt Flag */
        valid = TRUE;
      }

      if (valid)
      {
        osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_DEBOUNCE_VALUE);
      }
    }

    /**************************************************************************************************
    * @fn      HalKeyEnterSleep
    *
    * @brief  - Get called to enter sleep mode
    *
    * @param
    *
    * @return
    **************************************************************************************************/
    void HalKeyEnterSleep ( void )
    {
    }

    /**************************************************************************************************
    * @fn      HalKeyExitSleep
    *
    * @brief   - Get called when sleep is over
    *
    * @param
    *
    * @return  - return saved keys
    **************************************************************************************************/
    uint8 HalKeyExitSleep ( void )
    {
      /* Wake up and read keys */
      return ( HalKeyRead () );
    }

    /***************************************************************************************************
    *                                    INTERRUPT SERVICE ROUTINE
    ***************************************************************************************************/

    /**************************************************************************************************
    * @fn      halKeyPort0Isr
    *
    * @brief   Port0 ISR
    *
    * @param
    *
    * @return
    **************************************************************************************************/
    HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR )
    {
       if (HAL_KEY_SW_2_PXIFG & HAL_KEY_SW_2_BIT)
      {
        halProcessKeyInterrupt();
      }
       if (HAL_KEY_SW_3_PXIFG & HAL_KEY_SW_3_BIT)
      {
        halProcessKeyInterrupt();
      }
       if (HAL_KEY_SW_4_PXIFG & HAL_KEY_SW_4_BIT)
      {
        halProcessKeyInterrupt();
      }
       if (HAL_KEY_SW_5_PXIFG & HAL_KEY_SW_5_BIT)
      {
        halProcessKeyInterrupt();
      }
      if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT)
      {
        halProcessKeyInterrupt();
      }
      if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)
      {
        halProcessKeyInterrupt();
      }
      /*
        Clear the CPU interrupt flag for Port_0
        PxIFG has to be cleared before PxIF
      */
      HAL_KEY_SW_2_PXIFG = 0;
      HAL_KEY_SW_3_PXIFG = 0;
      HAL_KEY_SW_4_PXIFG = 0;
      HAL_KEY_SW_5_PXIFG = 0;
      HAL_KEY_SW_6_PXIFG = 0;
      HAL_KEY_SW_7_PXIFG = 0;
      HAL_KEY_CPU_PORT_0_IF = 0;
    }



    /**************************************************************************************************
    * @fn      halKeyPort2Isr
    *
    * @brief   Port2 ISR
    *
    * @param
    *
    * @return
    **************************************************************************************************/
    HAL_ISR_FUNCTION( halKeyPort2Isr, P2INT_VECTOR )
    {
      if (HAL_KEY_JOY_MOVE_PXIFG & HAL_KEY_JOY_MOVE_BIT)
      {
        halProcessKeyInterrupt();
      }

      /*
        Clear the CPU interrupt flag for Port_2
        PxIFG has to be cleared before PxIF
        Notes: P2_1 and P2_2 are debug lines.
      */
      HAL_KEY_JOY_MOVE_PXIFG = 0;
      HAL_KEY_CPU_PORT_2_IF = 0;
    }

    #else


    void HalKeyInit(void){}
    void HalKeyConfig(bool interruptEnable, halKeyCBack_t cback){}
    uint8 HalKeyRead(void){ return 0;}
    void HalKeyPoll(void){}

    #endif /* HAL_KEY */





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



    回复

    使用道具 举报

  • TA的每日心情
    开心
    2016-12-8 15:01
  • 签到天数: 459 天

    连续签到: 1 天

    [LV.9]以坛为家II

     楼主| 发表于 2013-12-26 17:18:19 | 显示全部楼层
    wudianjun2001 发表于 2013-12-26 17:17
    2530的硬件搞过,软件没接触过

    什么意思啊?这个也是硬件范畴啊。。指教下呗。。
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-11-25 17:29 , Processed in 0.125224 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.