添加按键

I want add a new key on port p1_6

cc2530EB, zstack2.3.0

#define HAL_KEY_SW_7_PORT P1
#define HAL_KEY_SW_7_BIT BV(6)
#define HAL_KEY_SW_7_SEL P1SEL
#define HAL_KEY_SW_7_DIR P1DIR

#define HAL_KEY_SW_7_EDGEBIT BV(2)
#define HAL_KEY_SW_7_EDGE HAL_KEY_FALLING_EDGE

#define HAL_KEY_SW_7_IEN IEN2 /* CPU interrupt mask register */
#define HAL_KEY_SW_7_IENBIT BV(4) /* Mask bit for all of Port_1 */
#define HAL_KEY_SW_7_ICTL P1IEN /* Port Interrupt Control register */
#define HAL_KEY_SW_7_ICTLBIT BV(6) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_7_PXIFG P1IFG /* Interrupt flag at source */

actually , I copied the #defines from HAL_KEY_SW_6

but something changed 

like #define HAL_KEY_SW_7_EDGEBIT BV(2) and  #define HAL_KEY_SW_7_IENBIT BV(4) 

I dont know why  HAL_KEY_SW_7_IENBIT is BV(4) and HAL_KEY_SW_6_IENBIT   is BV(5)

actually , I could not change these two defines, If I changed, the sw1 key (p0_1) and p1_6 wont work

anybody know why?

Now

in void HalKeyInit( void )

I also add 

HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT); /* Set pin function to GPIO */
HAL_KEY_SW_7_DIR &= ~(HAL_KEY_SW_7_BIT); /* Set pin direction to Input */

in  HalKeyConfig 

PICTL &= ~(HAL_KEY_SW_7_EDGEBIT); /* Clear the edge bit */
/* For falling edge, the bit must be set. */
#if (HAL_KEY_SW_7_EDGE == HAL_KEY_FALLING_EDGE)
PICTL |= HAL_KEY_SW_7_EDGEBIT;
#endif

HAL_KEY_SW_7_ICTL |= HAL_KEY_SW_7_ICTLBIT;
HAL_KEY_SW_7_IEN |= HAL_KEY_SW_7_IENBIT;
HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT);

in HalKeyRead 

//if (HAL_PUSH_BUTTON1())

if(!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT) )
{
   keys |= HAL_KEY_SW_6;
}

if (!(HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low *///,P1.6
{
   keys |= HAL_KEY_SW_7;
}

as you can see, I change HAL_KEY_SW_6  ,  from HAL_PUSH_BUTTON1 to !.....

in HalKeyPoll

//if (HAL_PUSH_BUTTON1())
if(!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT) )
{
  keys |= HAL_KEY_SW_6;
}

if (!(HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low *///,P1.6
// if( (!(P1_6)))
{
  keys |= HAL_KEY_SW_7;
}

nearly, I copied the process way as HAL_KEY_SW_6

in void halProcessKeyInterrupt (void)

if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) /* Interrupt Flag has been set */
{
 HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT); /* Clear Interrupt Flag */
 valid = TRUE;
}

then add a interrupt

HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
{

if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)
{
   halProcessKeyInterrupt();

}

/*
Clear the CPU interrupt flag for Port_0
PxIFG has to be cleared before PxIF
*/
  HAL_KEY_SW_7_PXIFG = 0;
  HAL_KEY_CPU_PORT_1_IF = 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值