void readCNAndClrIsr() { int portStatus = 0; portStatus = mPORTDRead(); //clear mismatch portStatus = mPORTBRead(); //clear mismatch mCNClearIntFlag(); }
// Configure the CN interrupt handler void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void) { unsigned int temp; // clear the mismatch condition temp = mPORTBRead(); // clear the interrupt flag mCNClearIntFlag(); // .. things to do .. if ( !(temp & (1<<2)) ) { //button on RB2 is pressed if (MotorsON == 0) MotorsON = 1; else MotorsON = 0; } if ( temp & (1<<3) ) { M1forward = 1; } else if ( !(temp & (1<<3)) ) { M1forward = 0; } if ( temp & (1<<4) ) { M2forward = 1; } else if ( !(temp & (1<<4)) ) { M2forward = 0; } }
void __ISR(_CHANGE_NOTICE_VECTOR, ipl6)IntCN(void) { mPORTDRead(); //mPORTDRead(); //Vaciar if (BUTTON_1) { PUSH_BUTTON_pressed = TRUE; } mCNClearIntFlag(); }
void setup_spi() { // TODO move it out of here INTDisableInterrupts(); mCNOpen(CN_ON | CN_IDLE_CON, CN1_ENABLE, CN1_PULLUP_ENABLE); mPORTCRead(); mCNSetIntPriority(6); // same as below mCNClearIntFlag(); mCNIntEnable(1); INTEnableInterrupts(); }
void __ISR(_CHANGE_NOTICE_VECTOR, ipl6) ChangeNotice_Handler(void) { // Step #1 - always clear the mismatch condition first int dummy = PORTReadBits(IOPORT_D, BIT_5);; // Step #2 - then clear the interrupt flag mCNClearIntFlag(); PORTF ^= BIT_0; }
/********************************************************************** * Function: Interrupt Service Routine for Override board * @return None * @remark ISR that is called when CH3 pings external interrupt * @author Darrel Deo * @date 2013.04.01 **********************************************************************/ void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void){ mPORTDRead(); //? Timer_new(TIMER_OVERRIDE, OVERRIDE_TIMEOUT_DELAY); //Clear the interrupt flag that was risen for the external interrupt //might want to set a timer in here mCNClearIntFlag(); //INTEnable(INT_CN,0); }
void __ISR(_CHANGE_NOTICE_VECTOR, ipl1) ChangeNotice_Handler(void) { BYTE temp; temp = mPORTDRead(); sendCard = 1; mCNClearIntFlag(); // clear the interrupt flag }
void setupCNModuleAndPIRInput() { //PIR Input and notification A1 mPORTBSetPinsDigitalIn(BIT_2); //A1 PIR Input (CN4 module) mCNOpen(CN_OFF | CN_IDLE_CON | CN_IDLE_CON, CN4_ENABLE, CN4_PULLUP_ENABLE); // read port(s) to clear mismatch mPORTBReadBits(BIT_2); // configure interrupts and clear change notice interrupt flag ConfigIntCN(CHANGE_INT_ON | CHANGE_INT_PRI_3); mCNClearIntFlag(); // Clear interrupt flag }
/** * Function: Interrupt Service Routine * @return None * @remark ISR that is called when CH3 pings external interrupt * @author Darrel Deo * @date 2013.04.01 */ void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void){ mPORTDRead(); Serial_putChar('Y'); //Change top-level state machine so it is in state Reciever CONTROL_MASTER = RECIEVER_CONTROL; OVERRIDE_TRIGGERED = TRUE; //Clear the interrupt flag that was risen for the external interrupt //might want to set a timer in here mCNClearIntFlag(); INTEnable(INT_CN,0); }
void BSP_CNHandler (void) { CPU_INT32U reg_val; reg_val = PORTD; /* Read register to clear change notice mismatch condition */ // if ((reg_val & PB0_MASK) == 0) { /* Insert your application code here */ /* Insert your application code here */ // } mCNClearIntFlag(); }
/*************************************************************************************************** InitKeyboard Initialise the keyboard and sound routines. ****************************************************************************************************/ void initKeyboard(void) { // enable pullups on the clock and data lines. // This stops them from floating and generating random chars when no keyboard is attached CNCONbits.ON = 1; // turn on Change Notification module P_PS2CLK_PULLUP = P_ON; // turn on the pullup for pin D6 also called CN15 P_PS2DAT_PULLUP = P_ON; // turn on the pullup for pin D7 also called CN16 // setup Change Notification interrupt P_PS2CLK_INT = P_ON; // enable PS2CLK (CN15) as a change interrupt mCNSetIntPriority(3); // set interrupt priority to 3 mCNClearIntFlag(); // clear the interrupt flag mCNIntEnable(1); // enable interrupt }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // STEP 9. configure the CN interrupt handler void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void) { unsigned int temp; // clear the mismatch condition temp = PORTReadBits(IOPORT_D, BIT_6); // .. things to do .. toggle the led mPORTDToggleBits(BIT_1); mPORTEToggleBits(BIT_2); // clear the interrupt flag mCNClearIntFlag(); }
void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void) { unsigned int temp; // clear the mismatch condition temp = mPORTDRead(); // clear the interrupt flag mCNClearIntFlag(); // .. things to do .. if ( !(temp & (1<<13)) ) { //button on RD13 is pressed if (Robo_State == 0) Robo_State = 1; else { Robo_State = 0; } } }
static void PB_IntInit (void) { CPU_INT32U dummy_read; CPU_INT16U config; config = CHANGE_INT_ON | CHANGE_INT_PRI_3; CNCON = 0x8000; /* Enable the change notice module */ EnableCN19(); /* Enable change notice pin 19, tied to our push button */ ConfigCNPullups(CN19_PULLUP_ENABLE); /* Enable a weak pull-up corresponding to the CN pin */ dummy_read = PORTD; /* Perform a dummy read to clear any mismatch conditions */ mCNClearIntFlag(); /* Clear the int flag just in case it was triggered */ ConfigIntCN(config); /* Enable CN interrupts at priority level 3 */ }
void setupCNModuleAnd_IR_PIR_Input() { //T2 used to sample IR Input signals setupTimer2(); //IR INPUT mPORTDSetPinsDigitalIn(BIT_7); //D5 IR Input (CN16 module, RD7) //PIR input mPORTBSetPinsDigitalIn(BIT_2); //A1 PIR Input (CN4 module, RB2) // setup the change notice options //(ensure that CN continues working in sleep mode) mCNOpen(CN_OFF | CN_IDLE_CON, CN16_ENABLE | CN4_ENABLE, CN16_PULLUP_ENABLE | CN4_PULLUP_ENABLE); // read port(s) to clear mismatch mPORTDReadBits(BIT_7); mPORTBReadBits(BIT_2); mPORTBReadBits(BIT_4); // configure interrupts and clear change notice interrupt flag ConfigIntCN(CHANGE_INT_ON | CHANGE_INT_PRI_3); mCNClearIntFlag(); // Clear interrupt flag }
void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void) { // Step #1 - always clear the mismatch condition first, by reading the port (or just the bit) dummy = PORTD; // Step #2 - then clear the interrupt flag mCNClearIntFlag(); // Step #3 - process the switches /* if(dummy == BIT_7) { PORTClearBits(IOPORT_D, BIT_1); // turn off LED2 DBPRINTF("Switch SW2 has been released. \n"); } else { PORTSetBits(IOPORT_D, BIT_1); // turn on LED2 DBPRINTF("Switch SW2 has been pressed. \n"); } */ if((dummy & BIT_6) == 0) // SW1 pressed? { contrastSetup(); } if((dummy & BIT_7) == 0) // SW2 pressed? { //waitForUser(); haltDisplay ^= 1; delay_ms(20); } // additional processing here... }
void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void) { if(InTheMiddleOfSomething) return; BYTE bVal; bVal = PORTReadBits(IOPORT_B, BIT_0 | BIT_3); Led2; /******************A front wall is detected******************/ // if(!FrontSensor && LeftSensor) { InTheMiddleOfSomething = fTrue; Led1; Led2Clr; //Reverse the motor SetRightSpeed(dtcMtrStopped); RightReverse; //SetRightDir(prtMtrRightDirClr); //Reverse SetRightSpeed(dtcMtrMedium); //mCNClearIntFlag(); //Wait until the turn is executed Wait_ms(TURN90); //Continue going straight SetRightSpeed(dtcMtrStopped); RightForward; //SetRightDir(prtMtrRightDirSet); //Forward SetRightSpeed(dtcMtrMedium); Led1Clr; InTheMiddleOfSomething = fFalse; mCNClearIntFlag(); return; } if(LeftSensor) { InTheMiddleOfSomething = fTrue; Led4; Led2Clr; //Run for a few moments to get around the corner Wait_ms(TURN90/2); //Stop it until the turn is completed SetLeftSpeed(dtcMtrStopped); Wait_ms(TURN90); //Continue going straight and wait to mare sure it can detect the new wall SetLeftSpeed(dtcMtrMedium); Wait_ms(TURN90/4); Led4Clr; InTheMiddleOfSomething = fFalse; } /* if(LeftSensor && FrontSensor) { SetLeftSpeed(dtcMtrStopped); SetRightSpeed(dtcMtrStopped); } else { if(LeftSensor) //Far left sensor -> hard left { SetLeftSpeed(dtcMtrMedium); } if(FrontSensor) //Far right sensor -> hard right { SetRightSpeed(dtcMtrMedium); } } */ mCNClearIntFlag(); }