使用自己的板子,直接配置寄存器驱动按键可以使用,但在OSAL中使用却没有反应,同样的OSAL程序在开发板中可以使用,请问可能是什么问题?按键端口都是P0.1。
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.
使用自己的板子,直接配置寄存器驱动按键可以使用,但在OSAL中使用却没有反应,同样的OSAL程序在开发板中可以使用,请问可能是什么问题?按键端口都是P0.1。
static void simpleBLECentral_HandleKeys( uint8 shift, uint8 keys )
{
(void)shift; // Intentionally unreferenced parameter
//HalLcdWriteStringValue( "key = 0x", keys, 16, HAL_LCD_LINE_2 );
// smartRF开发板上的S1 对应我们源码上的HAL_KEY_SW_6
if ( keys & HAL_KEY_SW_6 )
{
//HalLcdWriteString( "HAL_KEY_SW_6", HAL_LCD_LINE_3 );
HalLedSet(HAL_LED_1, HAL_LED_MODE_FLASH); // led1闪烁
HalLedSet(HAL_LED_2, HAL_LED_MODE_ON); // led2亮
}
嗯嗯,我就是用的hal_key.c上的SW_6(p0.1),来控制LED,相同的代码在开发板上是可以的,只是在我的电路上不可以,但直接配置的寄存器代码(没有OSAL)可以驱动按键
您可以看一下下面的回调函数。
/********************************************************************* * @fn OnBoard_KeyCallback * * @brief Callback service for keys * * @param keys - keys that were pressed * state - shifted * * @return void *********************************************************************/ void OnBoard_KeyCallback ( uint8 keys, uint8 state ) { uint8 shift; (void)state; // shift key (S1) is used to generate key interrupt // applications should not use S1 when key interrupt is enabled shift = (OnboardKeyIntEnable == HAL_KEY_INTERRUPT_ENABLE) ? false : ((keys & HAL_KEY_SW_6) ? true : false); if ( OnBoard_SendKeys( keys, shift ) != SUCCESS ) { // Process SW1 here if ( keys & HAL_KEY_SW_1 ) // Switch 1 { } // Process SW2 here if ( keys & HAL_KEY_SW_2 ) // Switch 2 { } // Process SW3 here if ( keys & HAL_KEY_SW_3 ) // Switch 3 { } // Process SW4 here if ( keys & HAL_KEY_SW_4 ) // Switch 4 { } // Process SW5 here if ( keys & HAL_KEY_SW_5 ) // Switch 5 { } // Process SW6 here if ( keys & HAL_KEY_SW_6 ) // Switch 6 { } } /* If any key is currently pressed down and interrupt is still enabled, disable interrupt and switch to polling */ if( keys != 0 ) { if( OnboardKeyIntEnable == HAL_KEY_INTERRUPT_ENABLE ) { OnboardKeyIntEnable = HAL_KEY_INTERRUPT_DISABLE; HalKeyConfig( OnboardKeyIntEnable, OnBoard_KeyCallback); } } /* If no key is currently pressed down and interrupt is disabled, enable interrupt and turn off polling */ else { if( OnboardKeyIntEnable == HAL_KEY_INTERRUPT_DISABLE ) { OnboardKeyIntEnable = HAL_KEY_INTERRUPT_ENABLE; HalKeyConfig( OnboardKeyIntEnable, OnBoard_KeyCallback); } } }
您可以尝试在上面的函数内直接对键值进行处理。