P0SEL &=0xBF;// 1011 1111 //设置P0_6为普通IO口
P0DIR &=0xBF;// 1011 1111 //设置P0_6为输入
P0INP &=0xBF;// 1011 1111 //设置P0_6为上拉输入
P2INP &=0xDF;// 1101 1111 //P0_6 EA=1;
P0IE=1;//开P0组的中断
P0IEN |= 0x40; //0100 0000 设置P0_6为中断方式 PICTL |=0x01;//把P0这一组配置成下降沿触发
请问我以上代码哪个地方有问题
YiKai Chen:
可以參考hal_key.c 裡面SW6的寫法、SW6用的是P0.1、你只要把BV(1)改成BV(6)就是P0.6下降沿触发
Susan Yang:
建议您参考协议栈内的写法
/* 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 */