本实验是基于ZStack-CC2530-2.5.1a版本的协议栈来进行实验的,整个实验需要改动
hal_board_cfg.h、hal_board_cfg.h、hal_key.c、hal_key.h和自己定义的Coordinator.c这5个文件。
注意:添加自己的按键时尽量不要修改协议栈里面的按键程序,自己另行添加即可。
1、hal_key.h
在/* Switches (keys) */下面添加自己的按键定义
#define HAL_KEY_SW_8 0x80
图1:
----------------------------------------------------------------------------------------
2、hal_board_cfg.h
在/* S6 */
#define PUSH1_BV BV(1)
#define PUSH1_SBIT P0_1
#if defined (HAL_BOARD_CC2530EB_REV17)
#define PUSH1_POLARITY ACTIVE_LOW
#elif defined (HAL_BOARD_CC2530EB_REV13)
#define PUSH1_POLARITY ACTIVE_LOW
#else
#error Unknown Board Indentifier
#endif
下面模仿/* S6 */下的程序定义自己的按键值:
/* S8 */
#define PUSH8_BV BV(4)//修改
#define PUSH8_SBIT P0_4//修改
#if defined (HAL_BOARD_CC2530EB_REV17)
#define PUSH8_POLARITY ACTIVE_HIGH
#elif defined (HAL_BOARD_CC2530EB_REV13)
#define PUSH8_POLARITY ACTIVE_LOW
#else
#error Unknown Board Indentifier
#endif
图2:
------------------------------------------------------------------------------------------------------------- 在/* ----------- Push Buttons ---------- */
#define HAL_PUSH_BUTTON1() (PUSH1_POLARITY (PUSH1_SBIT))
#define HAL_PUSH_BUTTON2() (PUSH2_POLARITY (PUSH2_SBIT))
#define HAL_PUSH_BUTTON3() (0)
#define HAL_PUSH_BUTTON4() (0)
#define HAL_PUSH_BUTTON5() (0)
#define HAL_PUSH_BUTTON6() (0)
下定义自己的按键函数
#define HAL_PUSH_BUTTON8() (PUSH8_POLARITY (PUSH8_SBIT))
图3:
---------------------------------------------------------------------------------------------------------------- hal_key.c
在/* SW_6 is at P0.1 */
#define HAL_KEY_SW_6_PORT P0
#define HAL_KEY_SW_6_BIT 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
/* SW_6 interrupts */
#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(1) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_6_PXIFG P0IFG /* Interrupt flag at source */
下模仿/* SW_6 is at P0.1 */建立自己的按键函数
#define HAL_KEY_SW_8_PORT P0
#define HAL_KEY_SW_8_BIT BV(4) //修改
#define HAL_KEY_SW_8_SEL P0SEL
#define HAL_KEY_SW_8_DIR P0DIR
/* edge interrupt */