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

📄 hal_key.s51

📁 用IAR开发的ZIGBEE网络路由例子
💻 S51
📖 第 1 页 / 共 4 页
字号:
//  295        causes contant interruption on P2INT_VECTOR. Disable the usage of P2 interrupt
//  296        will stop this problem.
//  297     */
//  298     #if defined (HAL_BOARD_CC2430DB)
//  299       #define HAL_KEY_SW_5_ENABLE                     /* Allow SW5 only when key interrupt is disable */
//  300     #endif
//  301 
//  302 #if defined (HAL_KEY_SW_6_ENABLE)
//  303     HAL_KEY_SW_6_ICTL &= ~(HAL_KEY_SW_6_ICTLBIT);     /* Clear interrupt enable bit */
//  304     HAL_KEY_SW_6_IEN &= ~(HAL_KEY_SW_6_IENBIT);
//  305 #endif
//  306 
//  307 #if defined (HAL_KEY_SW_5_ENABLE)
//  308     HAL_KEY_SW_5_ICTL &= ~(HAL_KEY_SW_5_ICTLBIT);     /* Clear interrupt enable bit */
//  309     HAL_KEY_SW_5_IEN &= ~(HAL_KEY_SW_5_IENBIT);
//  310 #endif
//  311     osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_POLLING_VALUE);    /* Kick off polling */
//  312   }
//  313 
//  314   /* Key now is configured */
//  315   HalKeyConfigured = TRUE;
//  316 #endif /* HAL_KEY */
//  317 }
        LJMP	?BRET
        CFI EndBlock cfiBlock1
//  318 
//  319 /**************************************************************************************************
//  320  * @fn      HalKeyRead
//  321  *
//  322  * @brief   Read the current value of a key
//  323  *
//  324  * @param   None
//  325  *
//  326  * @return  keys - current keys status
//  327  **************************************************************************************************/
//  328 

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  329 uint8 HalKeyRead ( void )
HalKeyRead:
//  330 {
        ; Saved register size: 0
        ; Auto size: 0
//  331 
//  332   uint8 keys = 0;
//  333 
//  334 #if (HAL_KEY == TRUE)
//  335 
//  336 #if defined (HAL_KEY_JOYSTICK_ENABLE)
//  337   uint8 ksave0 = 0;
//  338   uint8 ksave1;
//  339   uint8 adc;
//  340 #endif
//  341 
//  342 #if defined (HAL_KEY_SW_6_ENABLE)
//  343   if (!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT))    /* Key is active low */
//  344   {
//  345     keys |= HAL_KEY_SW_6;
//  346   }
//  347 #endif
//  348 #if defined (HAL_KEY_SW_5_ENABLE)
//  349   if (HAL_KEY_SW_5_PORT & HAL_KEY_SW_5_BIT)       /* Key is active high */
//  350   {
//  351     keys |= HAL_KEY_SW_5;
//  352   }
//  353 #endif
//  354 
//  355 #if defined (HAL_KEY_JOYSTICK_ENABLE)
//  356 /*
//  357 *  The joystick control is encoded as an analog voltage.  Keep on reading
//  358 *  the ADC until two consecutive key decisions are the same.
//  359 */
//  360 
//  361   do
//  362   {
//  363     ksave1 = ksave0;    /* save previouse key reading */
//  364 
//  365     adc = HalAdcRead (HAL_KEY_JOY_CHN, HAL_ADC_RESOLUTION_8);
//  366 
//  367     if  (CHVER == 0x01)
//  368     {
//  369       /* Rev B */
//  370       if ((adc >= 90) && (adc <= 100))
//  371       {
//  372          ksave0 |= HAL_KEY_UP;
//  373       }
//  374       else if ((adc >= 75) && (adc <= 85))
//  375       {
//  376         ksave0 |= HAL_KEY_RIGHT;
//  377       }
//  378       else if ((adc >= 45) && (adc <= 55))
//  379       {
//  380         ksave0 |= HAL_KEY_LEFT;
//  381       }
//  382       else if (adc <= 10)
//  383       {
//  384         ksave0 |= HAL_KEY_DOWN;
//  385       }
//  386       else if ((adc >= 101) && (adc <= 115))
//  387       {
//  388       }
//  389     }
//  390     else
//  391     {
//  392        /* Rev C */
//  393       if ((adc >= 90)  && (adc <= 104))
//  394       {
//  395          ksave0 |= HAL_KEY_UP;
//  396       }
//  397       else if ((adc >= 75)  && (adc <= 89))
//  398       {
//  399         ksave0 |= HAL_KEY_RIGHT;
//  400       }
//  401       else if ((adc >= 45)  && (adc <= 56))
//  402       {
//  403         ksave0 |= HAL_KEY_LEFT;
//  404       }
//  405       else if (adc <= 10)
//  406       {
//  407         ksave0 |= HAL_KEY_DOWN;
//  408       }
//  409       else if ((adc >= 105) && (adc <= 121))
//  410       {
//  411       }
//  412     }
//  413 
//  414   } while (ksave0 != ksave1);
//  415 
//  416   keys |= ksave0;
//  417 
//  418 #endif
//  419 
//  420 #endif /* HAL_KEY */
//  421 
//  422   return keys;
        REQUIRE ?Subroutine0
        ; // Fall through to label ?Subroutine0

        RSEG BANKED_CODE:CODE:NOROOT(0)
?Subroutine0:
        CFI Block cfiBlock2 Using cfiCommon0
        CFI NoFunction
        MOV	R1,#0x0
        LJMP	?BRET
        CFI EndBlock cfiBlock2
//  423 
//  424 }
//  425 
//  426 
//  427 /**************************************************************************************************
//  428  * @fn      HalKeyPoll
//  429  *
//  430  * @brief   Called by hal_driver to poll the keys
//  431  *
//  432  * @param   None
//  433  *
//  434  * @return  None
//  435  **************************************************************************************************/

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  436 void HalKeyPoll (void)
HalKeyPoll:
        CFI Block cfiBlock3 Using cfiCommon0
        CFI Function HalKeyPoll
//  437 {
        ; Saved register size: 0
        ; Auto size: 0
//  438 #if (HAL_KEY == TRUE)
//  439 
//  440   uint8 keys = 0;
//  441 
//  442 #if defined (HAL_KEY_JOYSTICK_ENABLE)
//  443   uint8 ksave0 = 0;
//  444   uint8 ksave1;
//  445   uint8 adc;
//  446 #endif
//  447 
//  448   /*
//  449   *  If interrupts are enabled, get the status of the interrupt-driven keys from 'halSaveIntKey'
//  450   *  which is updated by the key ISR.  If Polling, read these keys directly.
//  451   */
//  452 #if defined (HAL_KEY_SW_6_ENABLE)
//  453   if (!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT))    /* Key is active low */
//  454   {
//  455     keys |= HAL_KEY_SW_6;
//  456   }
//  457 #endif
//  458 #if defined (HAL_KEY_SW_5_ENABLE)
//  459   if (HAL_KEY_SW_5_PORT & HAL_KEY_SW_5_BIT)       /* Key is active high */
//  460   {
//  461     keys |= HAL_KEY_SW_5;
//  462   }
//  463 #endif
//  464 
//  465 #if defined (HAL_KEY_JOYSTICK_ENABLE)
//  466 /*
//  467 *  The joystick control is encoded as an analog voltage.  Keep on reading
//  468 *  the ADC until two consecutive key decisions are the same.
//  469 */
//  470 
//  471   do
//  472   {
//  473     ksave1 = ksave0;    /* save previouse key reading */
//  474 
//  475     adc = HalAdcRead (HAL_KEY_JOY_CHN, HAL_ADC_RESOLUTION_8);
//  476 
//  477     if  (CHVER == 0x01)
//  478     {
//  479       /* Rev B */
//  480       if ((adc >= 90) && (adc <= 100))
//  481       {
//  482          ksave0 |= HAL_KEY_UP;
//  483       }
//  484       else if ((adc >= 75) && (adc <= 85))
//  485       {
//  486         ksave0 |= HAL_KEY_RIGHT;
//  487       }
//  488       else if ((adc >= 45) && (adc <= 55))
//  489       {
//  490         ksave0 |= HAL_KEY_LEFT;
//  491       }
//  492       else if (adc <= 10)
//  493       {
//  494         ksave0 |= HAL_KEY_DOWN;
//  495       }
//  496       else if ((adc >= 101) && (adc <= 115))
//  497       {
//  498       }
//  499     }
//  500     else
//  501     {
//  502        /* Rev C */
//  503       if ((adc >= 90)  && (adc <= 104))
//  504       {
//  505          ksave0 |= HAL_KEY_UP;
//  506       }
//  507       else if ((adc >= 75)  && (adc <= 89))
//  508       {
//  509         ksave0 |= HAL_KEY_RIGHT;
//  510       }
//  511       else if ((adc >= 45)  && (adc <= 56))
//  512       {
//  513         ksave0 |= HAL_KEY_LEFT;
//  514       }
//  515       else if (adc <= 10)
//  516       {
//  517         ksave0 |= HAL_KEY_DOWN;
//  518       }
//  519       else if ((adc >= 105) && (adc <= 121))
//  520       {
//  521       }
//  522     }
//  523 
//  524 
//  525   } while (ksave0 != ksave1);
//  526 
//  527   keys |= ksave0;
//  528 
//  529 #endif
//  530 
//  531   /* Exit if polling and no keys have changed */
//  532   if (!Hal_KeyIntEnable)
//  533   {
//  534     if (keys == halKeySavedKeys)
//  535     {
//  536       return;
//  537     }
//  538     halKeySavedKeys = keys;     /* Store the current keys for comparation next time */
//  539   }
//  540 
//  541   /* Invoke Callback if new keys were depressed */
//  542   if (keys && (pHalKeyProcessFunction))
//  543   {
//  544     (pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL);
//  545   }
//  546 
//  547 #endif /* HAL_KEY */
//  548 
//  549 }
        LJMP	?BRET
        CFI EndBlock cfiBlock3
//  550 
//  551 
//  552 /**************************************************************************************************
//  553  * @fn      halProcessKeyInterrupt
//  554  *
//  555  * @brief   Checks to see if it's a valid key interrupt, saves interrupt driven key states for
//  556  *          processing by HalKeyRead(), and debounces keys by scheduling HalKeyRead() 25ms later.
//  557  *
//  558  * @param
//  559  *
//  560  * @return
//  561  **************************************************************************************************/

        RSEG BANKED_CODE:CODE:NOROOT(0)
//  562 void halProcessKeyInterrupt (void)
halProcessKeyInterrupt:
        CFI Block cfiBlock4 Using cfiCommon0
        CFI Function halProcessKeyInterrupt
//  563 {
        ; Saved register size: 0
        ; Auto size: 0
//  564 
//  565 #if (HAL_KEY == TRUE)
//  566 
//  567   bool    valid=FALSE;
//  568 
//  569 #if defined (HAL_KEY_SW_6_ENABLE)
//  570   if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT)      /* Interrupt Flag has been set */
//  571   {
//  572     HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT);    /* Clear Interrupt Flag */
//  573     valid = TRUE;
//  574   }
//  575 #endif
//  576 
//  577 #if defined (HAL_KEY_SW_5_ENABLE)

⌨️ 快捷键说明

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