怎么将P1口设为外部中断呢?就像P0口的按键一样使用,试了几天了还是不行。
求TI的工程师和路过的各位大神能指点一下
Susan Yang:
把程序贴出来看看
Amos Chen:
回复 Susan Yang:
好的,下面就是我改动的程序:
/* CPU port interrupt */#define HAL_KEY_CPU_PORT_0_IF P0IF#define HAL_KEY_CPU_PORT_1_IF P2IF#define HAL_KEY_CPU_PORT_2_IF P2IF
#if defined ( CC2540_MINIDK )||( WEBEE_BOARD )/* 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
/* SW_2 is at P1.6 */#define HAL_KEY_SW_2_PORT P1#define HAL_KEY_SW_2_BIT BV(6)#define HAL_KEY_SW_2_SEL P1SEL#define HAL_KEY_SW_2_DIR P1DIR
#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 */#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(6) /* P0IEN – P0.1 enable/disable bit */#define HAL_KEY_SW_2_IENBIT BV(4) /* Mask bit for all of Port_0 */#define HAL_KEY_SW_2_PXIFG P1IFG /* Interrupt flag at source */
#define HAL_KEY_SW_1_EDGEBIT BV(0)
#else
//P0口中断程序
HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR ){ HAL_ENTER_ISR();#if defined ( CC2540_MINIDK )||( WEBEE_BOARD ) if ((HAL_KEY_SW_1_PXIFG & HAL_KEY_SW_1_BIT))#else if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT)#endif { halProcessKeyInterrupt(); }#if defined ( CC2540_MINIDK )||( WEBEE_BOARD ) HAL_KEY_SW_1_PXIFG = 0; HAL_KEY_SW_2_PXIFG = 0;#else HAL_KEY_SW_6_PXIFG = 0;#endif HAL_KEY_CPU_PORT_0_IF = 0; CLEAR_SLEEP_MODE(); HAL_EXIT_ISR(); return;}
//P1口中断程序HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR ){ HAL_ENTER_ISR();#if defined ( CC2540_MINIDK )||( WEBEE_BOARD ) 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(); }#if defined ( CC2540_MINIDK )||( WEBEE_BOARD ) HAL_KEY_SW_1_PXIFG = 0; 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;}
//下面的是初始化部分
P0SEL = 0; // Configure Port 0 as GPIO P1SEL = 0; // Configure Port 1 as GPIO P2SEL = 0; // Configure Port 2 as GPIO
P0DIR = 0xFC; P1DIR = 0xBF; P2DIR = 0x1F;
P0 = 0x03; P1 = 0x40; P2 = 0;
// 这里是按键的函数
#if defined( CC2540_MINIDK )||( WEBEE_BOARD )int num;static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys ){ VOID shift; // Intentionally unreferenced parameter
if (keys & HAL_KEY_SW_1) { num–; } if(keys & HAL_KEY_SW_2) { num++; } }#endif
所有改动的部分都在这里了,麻烦您帮忙看看问题究竟在哪?我看了好多次了还是不行,谢谢了
da qin zheng sheng:
在cc2540 usb dongle 测试通过!
中断功能:按键闪灯!
#include "ioCC2540.h" void delay(void) {unsigned long i; for(i=0;i<100000;i++) asm(" nop "); }#pragma vector = P1INT_VECTOR
__interrupt void P1INT_ISR(void){P1IFG=0;P1IF=0; P0=0; delay(); delay(); delay(); P0=0xff; delay(); delay(); delay(); } void main() { P0SEL =0; P1SEL =0x0; P0DIR=0xff; P1DIR=0x02; PICTL = 0x02;P1IEN=0x0c; IEN2=0x10; EA=1; while(1) { } }
Amos Chen:
回复 da qin zheng sheng:
谢谢了,大秦正声,在单片机上运行的程序我也做过,并且可以使用,但是在协议栈上就不行了,不知道是怎么回事,可以在帮忙看看吗?
da qin zheng sheng:
回复 Amos Chen:
估计老外的库函数有问题!
wenzhong shen:
http://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/p/68255/161765.aspx#161765 请看我原来回答的帖子,帖子是将P0的按键换成P1的。
另外老外的函数看起来拐弯很多,但是读懂之后,修改就很通用,只需改挤出宏定义即可。逻辑性很强
Amos Chen:
回复 wenzhong shen:
谢谢各位了,问题已经解决了,谢谢
supcond:
回复 Amos Chen:
请问一下你是怎么解决的?我也遇到了相同的问题,是在centrl中无法正常工作,p1.7根本没办法拉高,设置上升沿中断,其他口,一次向下按键会触发两次中断,但松开时没有中断,谢谢