P1SEL &= ~0x04; //set P1.2 as GPIO P1DIR &= ~0x04; // set P1.2 as input /* PIR sensor is connected to port P1.2*/ #define PIR_SENSOR_PORT P1 #define PIR_SENSOR_BIT BV(2) #define PIR_SENSOR_SEL P1SEL #define PIR_SENSOR_DIR P1DIR #define HAL_KEY_RISING_EDGE 0 /* edge interrupt */ #define PIR_SENSOR_EDGEBIT BV(1) #define PIR_SENSOR_EDGE HAL_KEY_RISING_EDGE #define PIR_SENSOR_IEN IEN2 /* CPU interrupt mask register */ #define PIR_SENSOR_IENBIT BV(4) /* Mask bit for all of Port_1 */ #define PIR_SENSOR_ICTL P1IEN /* Port Interrupt Control register */ #define PIR_SENSOR_ICTLBIT BV(2) /* P1IEN - P1.2 enable/disable bit */ #define PIR_SENSOR_PXIFG P1IFG /* Interrupt flag at source */ #define PIR_SENSOR_CPU_PORT_1_IF P1IF void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback) { . . PICTL &= ~(PIR_SENSOR_EDGEBIT); //clear edge bit for pir sensor #if (PIR_SENSOR_EDGE == HAL_KEY_FALLING_EDGE) PICTL |= PIR_SENSOR_EDGEBIT; #endif PIR_SENSOR_ICTL |= PIR_SENSOR_ICTLBIT; PIR_SENSOR_IEN |= PIR_SENSOR_IENBIT; PIR_SENSOR_PXIFG &= ~(PIR_SENSOR_BIT); . . } HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR ) { HAL_ENTER_ISR(); if(if (PIR_SENSOR_PXIFG & PIR_SENSOR_BIT) { . . } PIR_SENSOR_PXIFG = ~(PIR_SENSOR_BIT); PIR_SENSOR_CPU_PORT_1_IF = 0; CLEAR_SLEEP_MODE(); HAL_EXIT_ISR(); }