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

📄 hal_key.lst

📁 cc2430应用实例
💻 LST
📖 第 1 页 / 共 5 页
字号:
     64          #include "hal_adc.h"
     65          #include "hal_key.h"
     66          #include "osal.h"
     67          
     68          /**************************************************************************************************
     69           *                                              MACROS
     70           **************************************************************************************************/
     71          
     72          /**************************************************************************************************
     73           *                                            CONSTANTS
     74           **************************************************************************************************/
     75          #define HAL_KEY_BIT0   0x01
     76          #define HAL_KEY_BIT1   0x02
     77          #define HAL_KEY_BIT2   0x04
     78          #define HAL_KEY_BIT3   0x08
     79          #define HAL_KEY_BIT4   0x10
     80          #define HAL_KEY_BIT5   0x20
     81          #define HAL_KEY_BIT6   0x40
     82          #define HAL_KEY_BIT7   0x80
     83          
     84          #define HAL_KEY_RISING_EDGE   0
     85          #define HAL_KEY_FALLING_EDGE  1
     86          
     87          #define HAL_KEY_PDUP2           0x80
     88          #define HAL_KEY_PDUP1           0x40
     89          #define HAL_KEY_PDUP0           0x20
     90          
     91          #define HAL_KEY_DEBOUNCE_VALUE  25
     92          #define HAL_KEY_POLLING_VALUE   100
     93          
     94          
     95          #if defined (HAL_BOARD_CC2430DB)
     96            #define HAL_KEY_SW_6_ENABLE
     97            #define HAL_KEY_SW_6_PORT     P0                      /* Port location of SW1 */
     98            #define HAL_KEY_SW_6_BIT      HAL_KEY_BIT1            /* Bit location of SW1 */
     99            #define HAL_KEY_SW_6_SEL      P0SEL                   /* Port Select Register for SW1 */
    100            #define HAL_KEY_SW_6_DIR      P0DIR                   /* Port Direction Register for SW1 */
    101            #define HAL_KEY_SW_6_IEN      IEN1                    /* Interrupt Enable Register for SW1 */
    102            #define HAL_KEY_SW_6_IENBIT   HAL_KEY_BIT5            /* Interrupt Enable bit for SW1 */
    103            #define HAL_KEY_SW_6_EDGE     HAL_KEY_RISING_EDGE     /* Type of interrupt for SW1 */
    104            #define HAL_KEY_SW_6_EDGEBIT  HAL_KEY_BIT0            /* EdgeType enable bit SW1 */
    105            #define HAL_KEY_SW_6_ICTL     PICTL                   /* Port Interrupt Control for SW1 */
    106            #define HAL_KEY_SW_6_ICTLBIT  HAL_KEY_BIT3            /* Interrupt enable bit for SW1 */
    107            #define HAL_KEY_SW_6_PXIFG    P0IFG                   /* Port Interrupt Flag for SW1 */
    108          
    109            #define HAL_KEY_JOYSTICK_ENABLE
    110            #define HAL_KEY_JOY_CHN   HAL_ADC_CHANNEL_6
    111          
    112            #define HAL_KEY_SW_5_ENABLE   /* 2430DB - SW5 is enabled based on key interrupt enable or not - see config */
    113            #define HAL_KEY_SW_5_PORT     P2                      /* Port location of SW5 */
    114            #define HAL_KEY_SW_5_BIT      HAL_KEY_BIT0            /* Bit location of SW5 */
    115            #define HAL_KEY_SW_5_SEL      P2SEL                   /* Port Select Register for SW5 */
    116            #define HAL_KEY_SW_5_DIR      P2DIR                   /* Port Direction Register for SW5 */
    117            #define HAL_KEY_SW_5_INP      P2INP                   /* Port Input Mode Register for SW5 */
    118            #define HAL_KEY_SW_5_IEN      IEN2                    /* Interrupt Enable Register for SW5 */
    119            #define HAL_KEY_SW_5_IENBIT   HAL_KEY_BIT1            /* Interrupt Enable bit for SW5 */
    120            #define HAL_KEY_SW_5_EDGE     HAL_KEY_FALLING_EDGE    /* Type of interrupt for SW5 */
    121            #define HAL_KEY_SW_5_EDGEBIT  HAL_KEY_BIT2            /* EdgeType enable bit SW5 */
    122            #define HAL_KEY_SW_5_ICTL     PICTL                   /* Port Interrupt Control for SW5 */
    123            #define HAL_KEY_SW_5_ICTLBIT  HAL_KEY_BIT5            /* Interrupt enable bit for SW5 */
    124            #define HAL_KEY_SW_5_PXIFG    P2IFG                   /* Port Interrupt Flag for SW5 */
    125          
    126            #define HAL_KEY_P0INT_LOW_USED    HAL_KEY_SW_6_BIT    /* P0 can only be enabled/disabled as group of high or low nibble */
    127            #define HAL_KEY_POINT_HIGH_USED   0                   /* P0 can only be enabled/disabled as group of high or low nibble */
    128          #endif
    129          
    130          #if defined (HAL_BOARD_CC2430EB) || defined (HAL_BOARD_CC2430BB)
    131            #define HAL_KEY_SW_6_ENABLE
    132            #define HAL_KEY_SW_6_PORT     P0                      /* Port location of SW1 */
    133            #define HAL_KEY_SW_6_BIT      HAL_KEY_BIT1            /* Bit location of SW1 */
    134            #define HAL_KEY_SW_6_SEL      P0SEL                   /* Port Select Register for SW1 */
    135            #define HAL_KEY_SW_6_DIR      P0DIR                   /* Port Direction Register for SW1 */
    136            #define HAL_KEY_SW_6_IEN      IEN1                    /* Interrupt Enable Register for SW1 */
    137            #define HAL_KEY_SW_6_IENBIT   HAL_KEY_BIT5            /* Interrupt Enable bit for SW1 */
    138            #define HAL_KEY_SW_6_EDGE     HAL_KEY_RISING_EDGE     /* Type of interrupt for SW1 */
    139            #define HAL_KEY_SW_6_EDGEBIT  HAL_KEY_BIT0            /* EdgeType enable bit SW1 */
    140            #define HAL_KEY_SW_6_ICTL     PICTL                   /* Port Interrupt Control for SW1 */
    141            #define HAL_KEY_SW_6_ICTLBIT  HAL_KEY_BIT3            /* Interrupt enable bit for SW1 */
    142            #define HAL_KEY_SW_6_PXIFG    P0IFG                   /* Port Interrupt Flag for SW1 */
    143          
    144            #define HAL_KEY_P0INT_LOW_USED    HAL_KEY_SW_6_BIT    /* P0 can only be enabled/disabled as group of high or low nibble */
    145          #endif
    146          
    147          #if defined (HAL_BOARD_CC2430BB)
    148            #define HAL_KEY_POINT_HIGH_USED  0
    149          #endif
    150          
    151          #if defined (HAL_BOARD_CC2430EB)
    152            #define HAL_KEY_JOYSTICK_ENABLE
    153            #define HAL_KEY_JOY_CHN   HAL_ADC_CHANNEL_6
    154          
    155            #define HAL_KEY_SW_5_ENABLE
    156            #define HAL_KEY_SW_5_PORT     P0                      /* Port location of SW5 */
    157            #define HAL_KEY_SW_5_BIT      HAL_KEY_BIT5            /* Bit location of SW5 */
    158            #define HAL_KEY_SW_5_SEL      P0SEL                   /* Port Select Register for SW5 */
    159            #define HAL_KEY_SW_5_DIR      P0DIR                   /* Port Direction Register for SW5 */
    160            #define HAL_KEY_SW_5_INP      P0INP                   /* Port Input Mode Register for SW5 */
    161            #define HAL_KEY_SW_5_IEN      IEN1                    /* Interrupt Enable Register for SW5 */
    162            #define HAL_KEY_SW_5_IENBIT   HAL_KEY_BIT5            /* Interrupt Enable bit for SW5 */
    163            #define HAL_KEY_SW_5_EDGE     HAL_KEY_RISING_EDGE     /* Type of interrupt for SW5 */
    164            #define HAL_KEY_SW_5_EDGEBIT  HAL_KEY_BIT2            /* EdgeType enable bit SW5 */
    165            #define HAL_KEY_SW_5_ICTL     PICTL                   /* Port Interrupt Control for SW5 */
    166            #define HAL_KEY_SW_5_ICTLBIT  HAL_KEY_BIT4            /* Interrupt enable bit for SW5 */
    167            #define HAL_KEY_SW_5_PXIFG    P0IFG                   /* Port Interrupt Flag for SW5 */
    168          
    169            #define HAL_KEY_POINT_HIGH_USED   HAL_KEY_SW_5_BIT    /* P0 can only be enabled/disabled as group of high or low nibble */
    170          #endif
    171          
    172          /**************************************************************************************************
    173           *                                            TYPEDEFS
    174           **************************************************************************************************/
    175          
    176          
    177          /**************************************************************************************************
    178           *                                        GLOBAL VARIABLES
    179           **************************************************************************************************/

   \                                 In segment XDATA_Z, align 1, keep-with-next
   \   000000                REQUIRE __INIT_XDATA_Z
    180          static uint8 halKeySavedKeys;     /* used to store previous key state in polling mode */
   \                     ??halKeySavedKeys:
   \   000000                DS 1

   \                                 In segment XDATA_Z, align 1, keep-with-next
   \   000000                REQUIRE __INIT_XDATA_Z
    181          static halKeyCBack_t pHalKeyProcessFunction;
   \                     ??pHalKeyProcessFunction:
   \   000000                DS 3

   \                                 In segment XDATA_Z, align 1, keep-with-next
   \   000000                REQUIRE __INIT_XDATA_Z
    182          bool Hal_KeyIntEnable;            /* interrupt enable/disable flag */
   \                     Hal_KeyIntEnable:
   \   000000                DS 1

   \                                 In segment XDATA_Z, align 1, keep-with-next
   \   000000                REQUIRE __INIT_XDATA_Z
    183          uint8 halSaveIntKey;              /* used by ISR to save state of interrupt-driven keys */
   \                     halSaveIntKey:
   \   000000                DS 1
    184          

   \                                 In segment XDATA_Z, align 1, keep-with-next
   \   000000                REQUIRE __INIT_XDATA_Z
    185          static uint8 HalKeyConfigured;
   \                     ??HalKeyConfigured:
   \   000000                DS 1
    186          
    187          /**************************************************************************************************
    188           *                                        FUNCTIONS - Local
    189           **************************************************************************************************/
    190          void halProcessKeyInterrupt (void);
    191          
    192          
    193          /**************************************************************************************************
    194           *                                        FUNCTIONS - API
    195           **************************************************************************************************/
    196          /**************************************************************************************************
    197           * @fn      HalKeyInit
    198           *
    199           * @brief   Initilize Key Service
    200           *
    201           * @param   none
    202           *
    203           * @return  None
    204           **************************************************************************************************/

   \                                 In segment BANKED_CODE, align 1, keep-with-next
    205          void HalKeyInit( void )
   \                     HalKeyInit:
    206          {
   \   000000   C082         PUSH    DPL
   \   000002   C083         PUSH    DPH
   \   000004                ; Saved register size: 2
   \   000004                ; Auto size: 0
    207          #if (HAL_KEY == TRUE)
    208            /* Initialize previous key to 0 */
    209            halKeySavedKeys = 0;
   \   000004   E4           CLR     A
   \   000005   90....       MOV     DPTR,#??halKeySavedKeys
   \   000008   F0           MOVX    @DPTR,A
    210          
    211          #if defined (HAL_KEY_SW_6_ENABLE)
    212            HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT);    /* Set pin function to GPIO */
   \   000009   53F3FD       ANL     0xf3,#0xfd
    213            HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT);    /* Set pin direction to Input */
   \   00000C   53FDFD       ANL     0xfd,#0xfd
    214          #endif
    215          
    216          #if defined (HAL_KEY_SW_5_ENABLE)
    217            HAL_KEY_SW_5_SEL &= ~(HAL_KEY_SW_5_BIT);    /* Set pin function to GPIO */
   \   00000F   53F5FE       ANL     0xf5,#0xfe
    218            HAL_KEY_SW_5_DIR &= ~(HAL_KEY_SW_5_BIT);    /* Set pin direction to Input */
   \   000012   53FFFE       ANL     0xff,#0xfe
    219            HAL_KEY_SW_5_INP |= HAL_KEY_SW_5_BIT;       /* Set pin input mode to tri-state */
   \   000015   43F701       ORL     0xf7,#0x1
    220          #endif
    221          
    222            /* Initialize callback function */
    223            pHalKeyProcessFunction  = NULL;
   \   000018   90....       MOV     DPTR,#??pHalKeyProcessFunction
   \   00001B   F0           MOVX    @DPTR,A
   \   00001C   A3           INC     DPTR
   \   00001D   F0           MOVX    @DPTR,A
   \   00001E   A3           INC     DPTR
   \   00001F   F0           MOVX    @DPTR,A
    224          
    225            /* Start with key is not configured */
    226            HalKeyConfigured = FALSE;
   \   000020   90....       MOV     DPTR,#??HalKeyConfigured
   \   000023   F0           MOVX    @DPTR,A
    227          #endif /* HAL_KEY */
    228          }
   \   000024                REQUIRE ?Subroutine1
   \   000024                ; // Fall through to label ?Subroutine1

   \                                 In segment BANKED_CODE, align 1, keep-with-next
   \                     ?Subroutine1:
   \   000000   D083         POP     DPH
   \   000002   D082         POP     DPL
   \   000004   02....       LJMP    ?BRET
    229          
    230          /**************************************************************************************************
    231           * @fn      HalKeyConfig
    232           *
    233           * @brief   Configure the Key serivce
    234           *
    235           * @param   interruptEnable - TRUE/FALSE, enable/disable interrupt
    236           *          cback - pointer to the CallBack function
    237           *
    238           * @return  None
    239           **************************************************************************************************/

   \                                 In segment BANKED_CODE, align 1, keep-with-next
    240          void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
   \                     HalKeyConfig:
    241          {
   \   000000   74F7         MOV     A,#-0x9
   \   000002   12....       LCALL   ?BANKED_ENTER_XDATA
   \   000005                ; Saved register size: 9
   \   000005                ; Auto size: 0

⌨️ 快捷键说明

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