cc254x之修改协议栈按键io

来源:互联网 发布:c专家编程怎么样 编辑:程序博客网 时间:2024/05/15 03:06

        协议栈demo中有按键的处理流程,所以项目中可以完全利用协议栈的流程实现自己的按键操作,如果自己硬件的io和协议栈对应开发板的io不一致,则需要修改按键io定义的文件。


         下面以协议栈1.4为例,实现按键2 从p0.1到p1.2的修改:


          首先找到按键定义的文件Hal_key.c          一定要选对自己芯片对应的文件,详细修改过程如下:


一、添加port1的中断标志寄存器  宏定义

#define HAL_KEY_CPU_PORT_1_IF P1IF


二、修改按键2   由p0.1到p1.2定义

#if defined ( CC2540_MINIDK )/* SW_1 is at P0.0 */#define HAL_KEY_SW_1_PORT   P0#define HAL_KEY_SW_1_BIT    BV(0)#define HAL_KEY_SW_1_SEL    P0SEL#define HAL_KEY_SW_1_DIR    P0DIR#if 0/* SW_2 is at P0.1 */#define HAL_KEY_SW_2_PORT   P0#define HAL_KEY_SW_2_BIT    BV(1)#define HAL_KEY_SW_2_SEL    P0SEL#define HAL_KEY_SW_2_DIR    P0DIR#else/* SW_2 is at P1.2 */#define HAL_KEY_SW_2_PORT   P1#define HAL_KEY_SW_2_BIT    BV(2)#define HAL_KEY_SW_2_SEL    P1SEL#define HAL_KEY_SW_2_DIR    P1DIR#endif#define HAL_KEY_SW_1_IEN      IEN1  /* CPU interrupt mask register */#define HAL_KEY_SW_1_ICTL     P0IEN /* Port Interrupt Control register */#define HAL_KEY_SW_1_ICTLBIT  BV(0) /* P0IEN - P0.0 enable/disable bit */#define HAL_KEY_SW_1_IENBIT   BV(5) /* Mask bit for all of Port_0 */#define HAL_KEY_SW_1_PXIFG    P0IFG /* Interrupt flag at source */#if 0#define HAL_KEY_SW_2_IEN      IEN1  /* CPU interrupt mask register */#define HAL_KEY_SW_2_ICTL     P0IEN /* Port Interrupt Control register */#define HAL_KEY_SW_2_ICTLBIT  BV(1) /* P0IEN - P0.1 enable/disable bit */#define HAL_KEY_SW_2_IENBIT   BV(5) /* Mask bit for all of Port_0 */#define HAL_KEY_SW_2_PXIFG    P0IFG /* Interrupt flag at source */#else#define HAL_KEY_SW_2_IEN      IEN2  /* CPU interrupt mask register */#define HAL_KEY_SW_2_ICTL     P1IEN /* Port Interrupt Control register */#define HAL_KEY_SW_2_ICTLBIT  BV(2) /* P0IEN - P1.2 enable/disable bit */#define HAL_KEY_SW_2_IENBIT   BV(4) /* Mask bit for all of Port_1 */#define HAL_KEY_SW_2_PXIFG    P1IFG /* Interrupt flag at source */#endif


三、添加选择p1.0--p1.3触发模式(上升沿or下降沿)

#define HAL_KEY_SW_1_EDGEBIT  BV(0)|BV(1)


四、初始化函数void HalKeyInit( void )中添加port1的中断使能功能

//add by allen  HAL_KEY_SW_2_IEN |= ( HAL_KEY_SW_2_IENBIT );   /* enable CPU interrupt */

五、添加port1的中断处理函数

//add by allenHAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR ){  HAL_ENTER_ISR();#if defined ( CC2540_MINIDK )  if (HAL_KEY_SW_2_PXIFG & HAL_KEY_SW_2_BIT)#else  if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT)#endif  {    halProcessKeyInterrupt();  }  /*    Clear the CPU interrupt flag for Port_0    PxIFG has to be cleared before PxIF  */#if defined ( CC2540_MINIDK )  HAL_KEY_SW_2_PXIFG = 0;#else  HAL_KEY_SW_6_PXIFG = 0;#endif  HAL_KEY_CPU_PORT_1_IF = 0;  CLEAR_SLEEP_MODE();  HAL_EXIT_ISR();  return;}


六、如果demo初始化函数中有关于port的定义 ,需要进行修改,也可以直接屏蔽



经过这几步,就可以利用demo中的按键回调函数处理按键事件了

0 0
原创粉丝点击