Esempio n. 1
0
__interrupt void Button1_ISR (void)
{
    WORD i;

    if (GPIO_getInterruptStatus (BUTTON1_PORT, BUTTON1_PIN)){
        for (i = 0x23FF; i > 0; i--){ //Cheap debounce.
        }
        if (GPIO_getInputPinValue(BUTTON1_PORT, BUTTON1_PIN)){
        	bButton1Pressed = TRUE;
        }
    }

    if (GPIO_getInterruptStatus (BUTTON2_PORT, BUTTON2_PIN)){
         for (i = 0x23FF; i > 0; i--){ //Cheap debounce.
         }
         if (GPIO_getInputPinValue(BUTTON2_PORT, BUTTON2_PIN)){
        	 bButton2Pressed = TRUE;
         }
     }

    GPIO_clearInterrupt(BUTTON2_PORT, BUTTON2_PIN);
     __bic_SR_register_on_exit(LPM3_bits);   //Wake main from LPMx

    GPIO_clearInterrupt(BUTTON1_PORT, BUTTON1_PIN);
    __bic_SR_register_on_exit(LPM3_bits);   //Wake main from LPMx
}
Esempio n. 2
0
void Port_1(void)
{
	uint16_t irqStatus=0;
	static uint32_t last_press=0;

	irqStatus=GPIO_getInterruptStatus(GPIO_PORT_P1,
			NDRDY_PIN | TEST_SW_PIN | RESET_SW_PIN |
			SIMTEST_SW_PIN | SIMRESET_SW_PIN);

	if (irqStatus & NDRDY_PIN) {
		readyForPSAData=true;
		timer_lastIRQ=timer_ms;
		goodTransfer=true;
		totalTXLEDLoops=0;
		GPIO_clearInterrupt(NDRDY_PORT,NDRDY_PIN);
	} else if ((irqStatus & TEST_SW_PIN) || (irqStatus & SIMTEST_SW_PIN)) {
		if (timer_ms-last_press>250) {
			testBtn=true;
			last_press=timer_ms;
		}
		GPIO_clearInterrupt(SIMTEST_SW_PORT,SIMTEST_SW_PIN);
		GPIO_clearInterrupt(TEST_SW_PORT,TEST_SW_PIN);
	} else if (irqStatus & RESET_SW_PIN) {
		resetBtn=true;
		GPIO_clearInterrupt(RESET_SW_PORT,RESET_SW_PIN);
	}


}
Esempio n. 3
0
void init()
{
  //initialise colour sensor
  sensorInit();
  //iniitalise interface
  InterfaceInit();
  //initialise servos for seperator and sorter
  servoInit();
  
  // Configure button S1 interrupt
  GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN3, GPIO_LOW_TO_HIGH_TRANSITION);
  GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3);  

  GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3);

  GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN3);
  
  // Configure button S2 interrupt
  GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN4, GPIO_LOW_TO_HIGH_TRANSITION);
  GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4);  

  GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN4);

  GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4);
}
void gpio_init_remote_dev(event_handler_t sw1_handler, event_handler_t sw2_handler, event_handler_t sw3_handler, event_handler_t sw4_handler, event_handler_t sw5_handler, event_handler_t sw6_handler, event_handler_t sw7_handler) {
	// Switch init
	GPIO_setAsInputPinWithPullUpResistor(SW1_PORT, SW1_PIN);
	GPIO_setAsInputPinWithPullUpResistor(SW2_PORT, SW2_PIN);
	GPIO_setAsInputPinWithPullUpResistor(SW3_PORT, SW3_PIN);
	GPIO_setAsInputPinWithPullUpResistor(SW4_PORT, SW4_PIN);
	GPIO_setAsInputPinWithPullUpResistor(SW5_PORT, SW5_PIN);
	/*
	GPIO_setAsInputPinWithPullUpResistor(SW6_PORT, SW6_PIN);
	GPIO_setAsInputPinWithPullUpResistor(SW7_PORT, SW7_PIN);
	*/
	GPIO_selectInterruptEdge(SW1_PORT, SW1_PIN, GPIO_HIGH_TO_LOW_TRANSITION);
	GPIO_selectInterruptEdge(SW2_PORT, SW2_PIN, GPIO_HIGH_TO_LOW_TRANSITION);
	GPIO_selectInterruptEdge(SW3_PORT, SW3_PIN, GPIO_HIGH_TO_LOW_TRANSITION);
	GPIO_selectInterruptEdge(SW4_PORT, SW4_PIN, GPIO_HIGH_TO_LOW_TRANSITION);
	GPIO_selectInterruptEdge(SW5_PORT, SW5_PIN, GPIO_HIGH_TO_LOW_TRANSITION);
	/*
	GPIO_selectInterruptEdge(SW6_PORT, SW6_PIN, GPIO_HIGH_TO_LOW_TRANSITION);
	GPIO_selectInterruptEdge(SW7_PORT, SW7_PIN, GPIO_HIGH_TO_LOW_TRANSITION);
	*/
	GPIO_clearInterrupt(SW1_PORT, SW1_PIN);
	GPIO_clearInterrupt(SW2_PORT, SW2_PIN);
	GPIO_clearInterrupt(SW3_PORT, SW3_PIN);
	GPIO_clearInterrupt(SW4_PORT, SW4_PIN);
	GPIO_clearInterrupt(SW5_PORT, SW5_PIN);
	/*
	GPIO_clearInterrupt(SW6_PORT, SW6_PIN);
	GPIO_clearInterrupt(SW7_PORT, SW7_PIN);
	*/
	GPIO_enableInterrupt(SW1_PORT, SW1_PIN);
	GPIO_enableInterrupt(SW2_PORT, SW2_PIN);
	GPIO_enableInterrupt(SW3_PORT, SW3_PIN);
	GPIO_enableInterrupt(SW4_PORT, SW4_PIN);
	GPIO_enableInterrupt(SW5_PORT, SW5_PIN);
	/*
	GPIO_enableInterrupt(SW6_PORT, SW6_PIN);
	GPIO_enableInterrupt(SW7_PORT, SW7_PIN);
	*/

	_sw1_event = event_add(sw1_handler);
	_sw2_event = event_add(sw2_handler);
	_sw3_event = event_add(sw3_handler);
	_sw4_event = event_add(sw4_handler);
	_sw5_event = event_add(sw5_handler);
	/*
	_sw6_event = event_add(sw6_handler);
	_sw7_event = event_add(sw7_handler);
	*/

	// LED init
	GPIO_setAsOutputPin(LED1_PORT, LED1_PIN);
	GPIO_setAsOutputPin(LED2_PORT, LED2_PIN);
	GPIO_setAsOutputPin(LED3_PORT, LED3_PIN);

	GPIO_setOutputLowOnPin(LED1_PORT, LED1_PIN);
	GPIO_setOutputLowOnPin(LED2_PORT, LED2_PIN);
	GPIO_setOutputLowOnPin(LED3_PORT, LED3_PIN);
}
Esempio n. 5
0
void initButtons(void)
{
	GPIO_setOutputHighOnPin(BUTTON1_PORT, BUTTON1_PIN);
	GPIO_setAsInputPinWithPullUpResistor(BUTTON1_PORT, BUTTON1_PIN);
	GPIO_clearInterrupt(BUTTON1_PORT, BUTTON1_PIN);
	GPIO_enableInterrupt(BUTTON1_PORT, BUTTON1_PIN);

	GPIO_setOutputHighOnPin(BUTTON2_PORT, BUTTON2_PIN);
	GPIO_setAsInputPinWithPullUpResistor(BUTTON2_PORT, BUTTON2_PIN);
	GPIO_clearInterrupt(BUTTON2_PORT, BUTTON2_PIN);
	GPIO_enableInterrupt(BUTTON2_PORT, BUTTON2_PIN);
}
Esempio n. 6
0
__interrupt void P1_ISR(void)
{
  switch(__even_in_range(P1IV,P1IV_P1IFG7)) 
  {
     case P1IV_P1IFG3: //It is SW1
      	SW1_interruptFlag_ = 1;
    	GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3);
      break;
      
      case P1IV_P1IFG4:  //It is SW2
    	SW2_interruptFlag_ = 1;
    	GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN4);
      break;
  } 

}
__interrupt void watchDogIsr(void)
{
	WDT_A_resetTimer(WDT_A_BASE);
	GPIO_clearInterrupt(PIRPORT, PIRPIN);
	GPIO_selectInterruptEdge(PIRPORT, PIRPIN, GPIO_LOW_TO_HIGH_TRANSITION);
	GPIO_enableInterrupt(PIRPORT, PIRPIN);
#if DEBUG
	GPIO_setOutputLowOnPin(LEDPORT, LEDPIN);
#endif
}
Esempio n. 8
0
void Port_2(void)
{
	uint16_t irqStatus=0;

	irqStatus=GPIO_getInterruptStatus(GPIO_PORT_P2,SIMRESET_SW_PIN);

	if (irqStatus & SIMRESET_SW_PIN) {
		resetBtn=true;
		GPIO_clearInterrupt(GPIO_PORT_P2,SIMRESET_SW_PIN);
	}

}
void Port_1(void)
{
    //P1.0 = toggle
    GPIO_toggleOutputOnPin(
        GPIO_PORT_P1,
        GPIO_PIN0
        );

    //P1.4 IFG cleared
    GPIO_clearInterrupt(
        GPIO_PORT_P1,
        GPIO_PIN4
        );
}
void main(void)
{
    //Stop watchdog timer
    WDT_A_hold(WDT_A_BASE);

    //Set P1.0 to output direction
    GPIO_setAsOutputPin(
        GPIO_PORT_P1,
        GPIO_PIN0
        );

    //Enable P1.4 internal resistance as pull-Up resistance
    GPIO_setAsInputPinWithPullUpResistor(
        GPIO_PORT_P1,
        GPIO_PIN4
        );

    //P1.4 interrupt enabled
    GPIO_enableInterrupt(
        GPIO_PORT_P1,
        GPIO_PIN4
        );

    //P1.4 Hi/Lo edge
    GPIO_selectInterruptEdge(
        GPIO_PORT_P1,
        GPIO_PIN4,
        GPIO_HIGH_TO_LOW_TRANSITION
        );

    //P1.4 IFG cleared
    GPIO_clearInterrupt(
        GPIO_PORT_P1,
        GPIO_PIN4
        );

    //Enter LPM4 w/interrupt
    __bis_SR_register(LPM4_bits + GIE);

    //For debugger
    __no_operation();
}