/**********************************************************************//** * @brief Initializes the System * * @param none * * @return none *************************************************************************/ void SystemInit(void) { // Set the DCO to 8MHz (it's also the device's power-on setting). Do not change this frequency! // It impacts the cap touch scan window. CS_setDCOFreq(__MSP430_BASEADDRESS_CS__, CS_DCORSEL_0, CS_DCOFSEL_6); // Configure clock source and clock dividers. After this the clock configuration will be as follows: // ACLK=LFXT1/1=32,768Hz; SMCLK=DCOCLK/1=8MHz; and MCLK=DCOCLK/1=8MHz. CS_clockSignalInit(__MSP430_BASEADDRESS_CS__, CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_clockSignalInit(__MSP430_BASEADDRESS_CS__, CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); CS_clockSignalInit(__MSP430_BASEADDRESS_CS__, CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // Set all GPIO to output low to minimize current draw by eliminating floating pins. GPIO_setOutputLowOnPin(GPIO_PORT_PA, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setOutputLowOnPin(GPIO_PORT_PB, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setOutputLowOnPin(GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setAsOutputPin(GPIO_PORT_PA, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setAsOutputPin(GPIO_PORT_PB, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); GPIO_setAsOutputPin(GPIO_PORT_PJ, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN6 | GPIO_PIN7 | GPIO_PIN8 | GPIO_PIN9 | GPIO_PIN10 | GPIO_PIN11 | GPIO_PIN12 | GPIO_PIN13 | GPIO_PIN14 | GPIO_PIN15); // Configure the left button (S2) connected to P4.6. For this enable the internal pull-up resistor and // setup the pin interrupt to trigger on rising edges. GPIO_setAsInputPinWithPullUpresistor(GPIO_PORT_P4, GPIO_PIN5); GPIO_interruptEdgeSelect(GPIO_PORT_P4, GPIO_PIN5, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_clearInterruptFlag(GPIO_PORT_P4, GPIO_PIN5); GPIO_enableInterrupt(GPIO_PORT_P4, GPIO_PIN5); // Configure the right button (S3) connected to P1.1. For this enable the internal pull-up resistor and // setup the pin interrupt to trigger on rising edges. GPIO_setAsInputPinWithPullUpresistor(GPIO_PORT_P1, GPIO_PIN1); GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN1, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1); // CapSense Setup. GPIO pins P1.3-1.5 and P3.4-3.6 are used for capacitive touch so let's // switch them to inputs. // GPIO_setAsInputPin(GPIO_PORT_P1, GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5); GPIO_setAsInputPin(GPIO_PORT_P3, GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6); // Enable LFXT functionality on PJ.4 and PJ.5. For this we only need to configure PJ.4 to // LFXIN and the port module logic takes care of the rest. GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_PJ, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION); // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings PMM_unlockLPM5(__MSP430_BASEADDRESS_PMM_FRAM__); // Perform the required LFXT startup procedure now that all of the port pins are configured. CS_setExternalClockSource(__MSP430_BASEADDRESS_CS__, 32768, 0); CS_LFXTStart(__MSP430_BASEADDRESS_CS__, CS_LFXT_DRIVE0); // Initialize LCD driver and the context for the LCD Sharp96x96_LCDInit(); TA0_enableVCOMToggle(); GrContextInit(&sContext, &g_sharp96x96LCD); GrContextForegroundSet(&sContext, ClrBlack); GrContextBackgroundSet(&sContext, ClrWhite); onLED(); //blink LED1 }
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); }
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); }
void Port2_Pin5_6_Init(){ //Enable Pin internal resistance as pull-Up resistance GPIO_setAsInputPinWithPullUpresistor( GPIO_PORT_P2, GPIO_PIN4 ); //Pin IFG cleared GPIO_clearInterruptFlag( GPIO_PORT_P2, GPIO_PIN4 ); //Pin interrupt enabled GPIO_enableInterrupt( GPIO_PORT_P2, GPIO_PIN4 ); //Pin Hi/Lo edge GPIO_interruptEdgeSelect( GPIO_PORT_P2, GPIO_PIN4, GPIO_HIGH_TO_LOW_TRANSITION ); }
void button_enable_interrupts() { GPIO_enableInterrupt(INPUT1_BASEADDRESS, INPUT1_PORT, INPUT1_PIN); GPIO_enableInterrupt(INPUT2_BASEADDRESS, INPUT2_PORT, INPUT2_PIN); GPIO_enableInterrupt(INPUT3_BASEADDRESS, INPUT3_PORT, INPUT3_PIN); GPIO_interruptEdgeSelect(INPUT1_BASEADDRESS, INPUT1_PORT, INPUT1_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_interruptEdgeSelect(INPUT2_BASEADDRESS, INPUT2_PORT, INPUT2_PIN, GPIO_HIGH_TO_LOW_TRANSITION); GPIO_interruptEdgeSelect(INPUT3_BASEADDRESS, INPUT3_PORT, INPUT3_PIN, GPIO_HIGH_TO_LOW_TRANSITION); button_clear_interrupt_flag(); }
__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(); }
void buttonInit(void){ GPIO_setCallback(Board_BUTTON0, gpioButton0); GPIO_enableInt(Board_BUTTON0); /* Configure RGB LED pins */ GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN4 | GPIO_PIN6); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN6); /* Set RGB LED to red */ P2OUT |= BIT6; P2OUT &= ~BIT4; P5OUT &= ~BIT6; /* Setup Button */ GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P5,GPIO_PIN1); GPIO_clearInterruptFlag(GPIO_PORT_P5, GPIO_PIN1); GPIO_enableInterrupt(GPIO_PORT_P5, GPIO_PIN1); GPIO_interruptEdgeSelect(GPIO_PORT_P5, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION); Interrupt_enableInterrupt(INT_PORT5); }
/**********************************************************************//** * @brief Enables Right Switch * * @param none * * @return none *************************************************************************/ void EnableRightSwitch(void) { GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1); }
/**********************************************************************//** * @brief Enables Left Switch * * @param none * * @return none *************************************************************************/ void EnableLeftSwitch(void) { GPIO_clearInterruptFlag(GPIO_PORT_P4, GPIO_PIN5); GPIO_enableInterrupt(GPIO_PORT_P4, GPIO_PIN5); }