This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

2530开关灯的例程中HAL_KEY_SW_1到5分别对应哪个IO?

Other Parts Discussed in Thread: CC2530

static void zclSampleLight_HandleKeys( byte shift, byte keys )
{
  if ( keys & HAL_KEY_SW_1 )
  {
  }
  if ( keys & HAL_KEY_SW_2 )
  {
  }
  if ( keys & HAL_KEY_SW_3 )
  {
  }
  if ( keys & HAL_KEY_SW_4 )
  {
  }
  if ( shift && ( keys & HAL_KEY_SW_5 ) )
  {
  }
  else if ( keys & HAL_KEY_SW_5 )
  {
  }
}

  • 想基于zstack开关灯的例子做,CC2530的,通过检测2530某几个IO的输入电平,分析后再IO输出,

    考虑到IO引脚可能被复用了,我们准备把按键的IO用作输入,LED的IO用作输出,

    可是查了半天也没看出来按键和LED连到哪个IO,请问在哪里查找?hal_board_cfg.h里面没有定义

    1.HAL_KEY_SW_1到5可以用作IO去检测外部输入电平的高低吗?读输入IO的电平用哪个函数?

    2.HAL_LED_1到4是否可以用作输出高低电平?

  • /* 1 - Green */
    #define LED1_BV           BV(0)
    #define LED1_SBIT         P1_0
    #define LED1_DDR          P1DIR
    #define LED1_POLARITY     ACTIVE_HIGH
    
    #if defined (HAL_BOARD_CC2530EB_REV17)
      /* 2 - Red */
      #define LED2_BV           BV(1)
      #define LED2_SBIT         P1_1
      #define LED2_DDR          P1DIR
      #define LED2_POLARITY     ACTIVE_HIGH
    
      /* 3 - Yellow */
      #define LED3_BV           BV(4)
      #define LED3_SBIT         P1_4
      #define LED3_DDR          P1DIR
      #define LED3_POLARITY     ACTIVE_HIGH
    #endif
    
    /* ------------------------------------------------------------------------------------------------
     *                                    Push Button Configuration
     * ------------------------------------------------------------------------------------------------
     */
    
    #define ACTIVE_LOW        !
    #define ACTIVE_HIGH       !!    /* double negation forces result to be '1' */
    
    /* S1 */
    #define PUSH1_BV          BV(1)
    #define PUSH1_SBIT        P0_1
    
    #if defined (HAL_BOARD_CC2530EB_REV17)
      #define PUSH1_POLARITY    ACTIVE_HIGH
    #elif defined (HAL_BOARD_CC2530EB_REV13)
      #define PUSH1_POLARITY    ACTIVE_LOW
    #else
      #error Unknown Board Indentifier
    #endif
    
    /* Joystick Center Press */
    #define PUSH2_BV          BV(0)
    #define PUSH2_SBIT        P2_0
    #define PUSH2_POLARITY    ACTIVE_HIGH

    上述程序中说明了LED和按键占用的IO,您可以看一下

  • 谢谢,那个我看了,总共是3个LED和2个按键,但是
    HAL_KEY_SW_1到HAL_KEY_SW_5总共5个按键,IO分配的非别是?
    HAL_LED_1 到HAL_LED_14总共4个LED,对应的IO分别是?
  • 1. 按键的程序在hal_key.c
    2. LED IO引脚就是定義在hal_board_cfg.h
  • sw1-4是透過ADC去讀SmartRF05EB上的搖桿值來判定,SW5沒有對應,具體你可以去參考hal_key.c