协议栈按键轮询方式如何使用,中断方式ok,轮询不通
协议栈按键轮询方式如何使用,中断方式ok,轮询不通
外部按键在P06
修改如下
#define HAL_KEY_SW_6_PORT P0
#define HAL_KEY_SW_6_BIT BV(6) //BV(1)
#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_FALLING_EDGE
#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(6)//BV(1) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_6_PXIFG P0IFG
#define PUSH1_BV BV(6)//BV(1)
#define PUSH1_SBIT P0_6//P0_1
其他未修改,但是按下按键无法进入中断,
设置断点,系统可以进入轮询函数void HalKeyPoll (void)中
但是 在执行下列语句时,会直接return,将return注释掉,ok了,就变成了检测高电平
if (!Hal_KeyIntEnable)
{
if (keys == halKeySavedKeys)
{
/* Exit - since no keys have changed */
return;
}
/* Store the current keys for comparation next time */
halKeySavedKeys = keys;
}
Do you define
ISR_KEYINTERRUPT ?
I want to use key poll method instead of key interrupt, so i think i do not need to define ISR_KEYINTERRUT AM I RIGHT?
zstack default is key polling, so just change your key pin define.
you may set a breakpoint in HalKeyPoll() to watch.
yes i have changed pins and i set breakpoints in HalKeyPoll()
but it would jump HalKeyPoll() ,and when i comment sentence return, code is ok
if (!Hal_KeyIntEnable)
{
if (keys == halKeySavedKeys)
{
/* Exit - since no keys have changed */
return;
}
/* Store the current keys for comparation next time */
halKeySavedKeys = keys;
}
这个return进入是正常的,只有当按键按下的时候,不会进入了。
P0.6原先协议栈中,用作joystick的输入了,会不会这个影响了。