Пример #1
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);
}
Пример #3
0
/*
 *  ======== MSP_EXP430F5529LP_initWiFi ========
 */
void MSP_EXP430F5529LP_initWiFi(void)
{
    /* Configure EN & CS pins to disable CC3100 */
    GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN2);
    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN6);
    GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2);
    GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN6);

    /* Configure SPI */
    /* SPI CLK */
    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN2);
    /* MOSI/SIMO */
    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN0);
    /* MISO/SOMI */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN1);

    /* Configure IRQ pin */
    GPIO_setAsInputPinWithPullDownResistor(GPIO_PORT_P2, GPIO_PIN0);
    GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN0,
                             GPIO_LOW_TO_HIGH_TRANSITION);

    /* Initialize SPI and WiFi drivers */
    SPI_init();
    WiFi_init();
}
__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
}
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();
}