cc254x之修改协议栈按键io
2016-06-04 21:32
393 查看
协议栈demo中有按键的处理流程,所以项目中可以完全利用协议栈的流程实现自己的按键操作,如果自己硬件的io和协议栈对应开发板的io不一致,则需要修改按键io定义的文件。
下面以协议栈1.4为例,实现按键2 从p0.1到p1.2的修改:
首先找到按键定义的文件Hal_key.c 一定要选对自己芯片对应的文件,详细修改过程如下:
一、添加port1的中断标志寄存器 宏定义
二、修改按键2 由p0.1到p1.2定义
三、添加选择p1.0--p1.3触发模式(上升沿or下降沿)
四、初始化函数void HalKeyInit( void )中添加port1的中断使能功能
五、添加port1的中断处理函数
六、如果demo初始化函数中有关于port的定义 ,需要进行修改,也可以直接屏蔽
经过这几步,就可以利用demo中的按键回调函数处理按键事件了
下面以协议栈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 allen HAL_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中的按键回调函数处理按键事件了
相关文章推荐
- 104. Maximum Depth of Binary Tree
- 我思故我在
- 剑指Offer----面试题20:顺时针打印矩阵
- css样式之文本相关属性及边框相关属性
- 动态库的调试和崩溃的处理方法
- 258. Add Digits
- happygrep
- Android系统ViewGroup事件分发
- css样式字体相关属性及背景相关属性
- UITextView使用中的那些坑
- 292. Nim Game
- twitter heron流计算系统总结 基本框架(一) --- 纸上谈兵
- 基于Web的在线建模工具
- linux apache + mysql +php
- 线性回归
- Linux执行PHP脚本(简单实例)
- 自己动手写计算器V1.2
- XXencode 编码,XX编码介绍、XXencode编码转换原理与算法
- (loadrunner 一) 自带WebTours使用及异常解决办法汇总
- 迷宫算法c++实现