/**********************************************************************//** * @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 }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Set pin P1.0 to output direction and initialize low GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Set switch 2 (S2) as input button (connected to P1.1) GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P2, GPIO_PIN1 ); while(1) { // Read pin P1.1 which is connected to push button 2 usiButton1 = GPIO_getInputPinValue ( GPIO_PORT_P2, GPIO_PIN1 ); if ( usiButton1 == GPIO_INPUT_PIN_LOW ) { // If button is down, turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } else { // If button is up, turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); } } }
void gainSelectorLM94022(uint8_t gain) { /* Con esto podrí hacer una rutina q midiera VCC y A partir de esto * seleccionar la ganancia. */ switch (gain) { case VCC_SENSOR_1V5: GPIO_setOutputLowOnPin(GS_PORT,GS0); GPIO_setOutputLowOnPin(GS_PORT,GS1); break; case VCC_SENSOR_2V3: GPIO_setOutputHighOnPin(GS_PORT,GS0); GPIO_setOutputLowOnPin(GS_PORT,GS1); break; case VCC_SENSOR_3V0: GPIO_setOutputLowOnPin(GS_PORT,GS0); GPIO_setOutputHighOnPin(GS_PORT,GS1); break; case VCC_SENSOR_3V6: GPIO_setOutputHighOnPin(GS_PORT,GS0); GPIO_setOutputHighOnPin(GS_PORT,GS1); break; default: break; } }
void InitHardware(){ #ifdef __MSP430_HAS_PORT1_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT2_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT3_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT4_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT5_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT6_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P6, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P6, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT7_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P7, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P7, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT8_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT9_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P9, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P9, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORTJ_R__ GPIO_setOutputLowOnPin(GPIO_PORT_PJ, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_PJ, GPIO_ALL); #endif InitLED(); InitUserInputButtons(); InitBubbleSensor(); InitOcclusionSensor(); InitReservoirLevelPins(); InitMotor(); }
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); }
/* * This function drives all the I/O's as output-low, to avoid floating inputs * (which cause extra power to be consumed). This setting is compatible with * TI FET target boards, the F5529 Launchpad, and F5529 Experimenters Board; * but may not be compatible with custom hardware, which may have components * attached to the I/Os that could be affected by these settings. So if using * other boards, this function may need to be modified. */ void initPorts(void) { #ifdef __MSP430_HAS_PORT1_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT2_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT3_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT4_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT5_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT6_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P6, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P6, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT7_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P7, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P7, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT8_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORT9_R__ GPIO_setOutputLowOnPin(GPIO_PORT_P9, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_P9, GPIO_ALL); #endif #ifdef __MSP430_HAS_PORTJ_R__ GPIO_setOutputLowOnPin(GPIO_PORT_PJ, GPIO_ALL); GPIO_setAsOutputPin(GPIO_PORT_PJ, GPIO_ALL); #endif }
//***************************************************************************** // Initialize GPIO //***************************************************************************** void initGPIO(void) { // Set pin P1.0 to output direction and turn LED off GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); // Red LED (LED1) GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Set pin P4.7 to output direction and turn LED off GPIO_setAsOutputPin( GPIO_PORT_P4, GPIO_PIN7 ); // Green LED (LED2) GPIO_setOutputLowOnPin( GPIO_PORT_P4, GPIO_PIN7 ); // // Set P2.1 as input with pull-up resistor (for push button S1) // // configure interrupt on low-to-high transition // // and then clear flag and enable the interrupt // GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P2, GPIO_PIN1 ); // GPIO_selectInterruptEdge ( GPIO_PORT_P2, GPIO_PIN1, GPIO_LOW_TO_HIGH_TRANSITION ); // GPIO_clearInterrupt ( GPIO_PORT_P2, GPIO_PIN1 ); // GPIO_enableInterrupt ( GPIO_PORT_P2, GPIO_PIN1 ); // // Set P1.1 as input with pull-up resistor (for push button S2) // // configure interrupt on low-to-high transition // // and then clear flag and enable the interrupt // GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN1 ); // GPIO_selectInterruptEdge ( GPIO_PORT_P1, GPIO_PIN1, GPIO_LOW_TO_HIGH_TRANSITION ); // GPIO_clearInterrupt ( GPIO_PORT_P1, GPIO_PIN1 ); // GPIO_enableInterrupt ( GPIO_PORT_P1, GPIO_PIN1 ); // // Connect pins to clock crystals // GPIO_setAsPeripheralModuleFunctionInputPin( // GPIO_PORT_P5, // GPIO_PIN5 + // XOUT on P5.5 // GPIO_PIN4 + // XIN on P5.4 // GPIO_PIN3 + // XT2OUT on P5.3 // GPIO_PIN2 // XT2IN on P5.2 // ); // When running this lab exercise, you will need to pull the JP8 jumper and // use a jumper wire to connect signal from P1.3 (on boosterpack pinouts) to // JP8.2 (bottom pin) of LED1 jumper ... this lets the TA0.2 signal drive // LED1 directly (without having to use interrupts) GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P1, GPIO_PIN3 ); // // Output the ACLK and MCLK signals to their respective pins - which allows you to // // watch them with a logic analyzer (ACLK on P1.0, SMCLK on P2.2, MCLK on P7.7) // GPIO_setAsPeripheralModuleFunctionOutputPin( // GPIO_PORT_P1, // GPIO_PIN0 // ACLK on P1.0 (Shared with LED1 on jumper JP8) // ); // GPIO_setAsPeripheralModuleFunctionOutputPin( // GPIO_PORT_P2, // GPIO_PIN2 // SMCLK on P2.2 (Boosterpack - Right side (J5) pin 2) // ); }
void InitMotor(){ GPIO_setAsOutputPin( MOTOR_COIL_A1_PORT, MOTOR_COIL_A1_PIN ); GPIO_setAsOutputPin( MOTOR_COIL_A2_PORT, MOTOR_COIL_A2_PIN ); GPIO_setAsOutputPin( MOTOR_COIL_B1_PORT, MOTOR_COIL_B1_PIN ); GPIO_setAsOutputPin( MOTOR_COIL_B2_PORT, MOTOR_COIL_B2_PIN ); GPIO_setAsOutputPin( MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN ); GPIO_setOutputLowOnPin( MOTOR_COIL_A1_PORT, MOTOR_COIL_A1_PIN ); GPIO_setOutputLowOnPin( MOTOR_COIL_A2_PORT, MOTOR_COIL_A2_PIN ); GPIO_setOutputLowOnPin( MOTOR_COIL_B1_PORT, MOTOR_COIL_B1_PIN ); GPIO_setOutputLowOnPin( MOTOR_COIL_B2_PORT, MOTOR_COIL_B2_PIN ); GPIO_setOutputLowOnPin( MOTOR_ENABLE_PORT, MOTOR_ENABLE_PIN ); }
void led_off(unsigned char led_nr) { switch (led_nr) { case 1: OUTPUT1_TYPE == 0 ? GPIO_setOutputLowOnPin(OUTPUT1_BASEADDRESS, OUTPUT1_PORT, OUTPUT1_PIN): GPIO_setOutputHighOnPin(OUTPUT1_BASEADDRESS, OUTPUT1_PORT, OUTPUT1_PIN); break; case 2: OUTPUT2_TYPE == 0 ? GPIO_setOutputLowOnPin(OUTPUT2_BASEADDRESS, OUTPUT2_PORT, OUTPUT2_PIN): GPIO_setOutputHighOnPin(OUTPUT2_BASEADDRESS, OUTPUT2_PORT, OUTPUT2_PIN); break; case 3: OUTPUT3_TYPE == 0 ? GPIO_setOutputLowOnPin(OUTPUT3_BASEADDRESS, OUTPUT3_PORT, OUTPUT3_PIN): GPIO_setOutputHighOnPin(OUTPUT3_BASEADDRESS, OUTPUT3_PORT, OUTPUT3_PIN); break; } }
/* * ======== 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(); }
//***** Functions ************************************************************* void main (void) { // Stop watchdog timer // WDT_A_hold( WDT_A_BASE ); // Set pin P1.0 to output direction and initialize low // GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); // GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); initGPIO(); initClocks(); while(1) { // Turn on LED GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Wait about a second __delay_cycles( ONE_SECOND ); // Turn off LED GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); // Wait another second __delay_cycles( ONE_SECOND ); } }
/**********************************************************************//** * @brief turn off LED1 after user touch the Capsense * * @param none * * @return none *************************************************************************/ void offLED(void) { RTC_B_holdClock(__MSP430_BASEADDRESS_RTC_B__); RTC_B_disableInterrupt(__MSP430_BASEADDRESS_RTC_B__, RTC_B_PRESCALE_TIMER1_INTERRUPT); GPIO_setOutputLowOnPin(GPIO_PORT_PB, GPIO_PIN14); startupStatus = 0; }
int16_t getLDRVoltageForLED(uint8_t selectedPort, uint16_t selectedPins) { //enable desired pins to turn on LED GPIO_setOutputHighOnPin(selectedPort, selectedPins); //delay so LDR can settle __delay_cycles(LED_DELAY); //read from LDR ADC_startConversion(__MSP430_BASEADDRESS_ADC__,ADC_SINGLECHANNEL); //wait for completion interrupt from ADC while(!isADCFinished()) { __delay_cycles(1000); } int16_t temp = lastConversionValue(); //disable LED GPIO_setOutputLowOnPin(selectedPort, selectedPins); return temp; }
void TA1_0_IRQHandler(void) { GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); MAP_Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_0); }
//***************************************************************************** void initGPIO(void) { // Set pin P1.0 to output direction and turn off LED GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 ); __delay_cycles( HALF_SECOND ); }
__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 }
//----------------------------------------------------------------------- int RF_Init(void) { int err = 0; //Setting RGB LED as output MAP_GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); //Set P6.1 to be the pin interupt MAP_GPIO_setAsInputPin(GPIO_PORT_P6, GPIO_PIN1); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, GPIO_PIN1); MAP_GPIO_enableInterrupt(GPIO_PORT_P6, GPIO_PIN1); //Enable the gpio interupt MAP_Interrupt_enableInterrupt(INT_PORT6); MAP_Interrupt_enableMaster(); /* Initial values for nRF24L01+ library config variables */ rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit rf_addr_width = (uint8_t)PACKET_SIZE; rf_speed_power = RF24_SPEED_MIN | RF24_POWER_MAX; rf_channel = 120; msprf24_init(); // All RX pipes closed by default msprf24_set_pipe_packetsize(0, (uint8_t)PACKET_SIZE); msprf24_open_pipe(0, 1); // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs // Transmit to 'rad01' (0x72 0x61 0x64 0x30 0x31) msprf24_standby(); user = msprf24_current_state(); memcpy(addr, "\xDE\xAD\xBE\xEF\x01", 5); // addr[0] = 0xDE; addr[1] = 0xAD; addr[2] = 0xBE; addr[3] = 0xEF; addr[4] = 0x00; w_tx_addr(addr); w_rx_addr(0, addr); // Pipe 0 receives auto-ack's, autoacks are sent back to the TX addr so the PTX node // needs to listen to the TX addr on pipe#0 to receive them. msprf24_activate_rx(); return err; }
struct colour runSensor() { struct colour runResults; //enable lower bank LEDs GPIO_setOutputLowOnPin(RED_LED_PORT, RED_LED_PIN); GPIO_setOutputLowOnPin(GREEN_LED_PORT, GREEN_LED_PIN); GPIO_setOutputLowOnPin(BLUE_LED_PORT, BLUE_LED_PIN); /*RED LED***********************************************************/ runResults.red_value = getLDRVoltageForLED(RED_LED_PORT, RED_LED_PIN); /*GREEN LED********************************************************/ runResults.green_value = getLDRVoltageForLED(GREEN_LED_PORT, GREEN_LED_PIN); /*BLUE LED*********************************************************/ runResults.blue_value = getLDRVoltageForLED(BLUE_LED_PORT,BLUE_LED_PIN); return runResults; }
//------------------------------------------------------------------------------ // GPIO ISR void gpio_isr(void) { uint32_t status; status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P6); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P6, status); msprf24_get_irq_reason(); // this updates rf_irq if (rf_irq & RF24_IRQ_TX) { status = 1; GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1); } if (rf_irq & RF24_IRQ_TXFAILED) { status = 0; GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2); GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0); } msprf24_irq_clear(RF24_IRQ_MASK); // Clear any/all of them }
//***************************************************************************** // // Writes a command to the CFAF128128B-0145T. This function implements the basic SPI // interface to the LCD display. // //***************************************************************************** void HAL_LCD_writeCommand(uint8_t command) { // Set to command mode GPIO_setOutputLowOnPin(LCD_DC_PORT, LCD_DC_PIN); /* USCI_B0 TX buffer ready? */ while (!EUSCI_B_SPI_getInterruptStatus(LCD_EUSCI_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)); SPI_transmitData(LCD_EUSCI_BASE,command); // Set back to data mode GPIO_setOutputHighOnPin(LCD_DC_PORT, LCD_DC_PIN); }
void vParTestSetLED( UBaseType_t uxLED, BaseType_t xValue ) { if( uxLED < partstNUM_LEDS ) { if( xValue == pdFALSE ) { GPIO_setOutputLowOnPin( ucPorts[ uxLED ], usPins[ uxLED ] ); } else { GPIO_setOutputHighOnPin( ucPorts[ uxLED ], usPins[ uxLED ] ); } } }
void blinkGreenLED() { uint16_t i; GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN7); for (i = ((uint16_t)-1); i > 0; i--) { // cheap delay _NOP(); } GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN7); for (i = ((uint16_t)-1); i > 0; i--) { // cheap delay _NOP(); } }
void Toggle_ON_OFF_DS4_LED(void){ /*Scope: Toggles LED ON/OFF once when message received*/ /*Dependencies: #include <driverlib.h> config_DS4_LED(); */ GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); // Delay delay_LED(); // Toggle P1.0 output GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); // Delay delay_LED(); // Toggle P1.0 output GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); }
__interrupt void ADC12_ISR (void) { switch (__even_in_range(ADC12IV,34)){ case 0: break; //Vector 0: No interrupt case 2: break; //Vector 2: ADC overflow case 4: break; //Vector 4: ADC timing overflow case 6: //Vector 6: ADC12IFG0 //Is Memory Buffer 0 = A0 > 0.5AVcc? if (ADC12_getResults(__MSP430_BASEADDRESS_ADC12_PLUS__, ADC12_MEMORY_0) >= 0x7ff){ //set P1.0 GPIO_setOutputHighOnPin( __MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); } else { //Clear P1.0 LED off GPIO_setOutputLowOnPin( __MSP430_BASEADDRESS_PORT1_R__, GPIO_PORT_P1, GPIO_PIN0 ); } //Exit active CPU __bic_SR_register_on_exit(LPM0_bits); case 8: break; //Vector 8: ADC12IFG1 case 10: break; //Vector 10: ADC12IFG2 case 12: break; //Vector 12: ADC12IFG3 case 14: break; //Vector 14: ADC12IFG4 case 16: break; //Vector 16: ADC12IFG5 case 18: break; //Vector 18: ADC12IFG6 case 20: break; //Vector 20: ADC12IFG7 case 22: break; //Vector 22: ADC12IFG8 case 24: break; //Vector 24: ADC12IFG9 case 26: break; //Vector 26: ADC12IFG10 case 28: break; //Vector 28: ADC12IFG11 case 30: break; //Vector 30: ADC12IFG12 case 32: break; //Vector 32: ADC12IFG13 case 34: break; //Vector 34: ADC12IFG14 default: break; } }
////------------------------------------------------------------------------------ Fd_t spi_Open(void) { /* Selecting P9.5 P9.6 and P9.7 in SPI mode */ GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION); /* CS setup. */ GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN6); GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN6); /* Configuring SPI in 3wire master mode */ SPI_initMaster(EUSCI_B1_MODULE, &SDspiConfig); /* Enable SPI module */ SPI_enableModule(EUSCI_B1_MODULE); return 0;//NONOS_RET_OK; }
void testLedSet(LED_t led, bool on) { switch (led) { case Green: if (on) GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); else GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); break; case Red: break; case Yellow: break; } }
void HAL_LCD_SpiInit(void) { eUSCI_SPI_MasterConfig config = { EUSCI_B_SPI_CLOCKSOURCE_SMCLK, LCD_SYSTEM_CLOCK_SPEED, LCD_SPI_CLOCK_SPEED, EUSCI_B_SPI_MSB_FIRST, EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, EUSCI_B_SPI_3PIN }; SPI_initMaster(LCD_EUSCI_BASE, &config); SPI_enableModule(LCD_EUSCI_BASE); GPIO_setOutputLowOnPin(LCD_CS_PORT, LCD_CS_PIN); GPIO_setOutputHighOnPin(LCD_DC_PORT, LCD_DC_PIN); }
static void prvSetupHardware( void ) { /* Stop Watchdog timer. */ WDT_A_hold( __MSP430_BASEADDRESS_WDT_A__ ); /* Set all GPIO pins to output and low. */ GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P3, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P4, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_PJ, 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_P1, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P3, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_P4, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7 ); GPIO_setAsOutputPin( GPIO_PORT_PJ, 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 ); /* Configure P2.0 - UCA0TXD and P2.1 - UCA0RXD. */ GPIO_setOutputLowOnPin( GPIO_PORT_P2, GPIO_PIN0 ); GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN0 ); GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P2, GPIO_PIN1, GPIO_SECONDARY_MODULE_FUNCTION ); GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P2, GPIO_PIN0, GPIO_SECONDARY_MODULE_FUNCTION ); /* Set PJ.4 and PJ.5 for LFXT. */ GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_PJ, GPIO_PIN4 + GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION ); /* Set DCO frequency to 8 MHz. */ CS_setDCOFreq( CS_DCORSEL_0, CS_DCOFSEL_6 ); /* Set external clock frequency to 32.768 KHz. */ CS_setExternalClockSource( 32768, 0 ); /* Set ACLK = LFXT. */ CS_initClockSignal( CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1 ); /* Set SMCLK = DCO with frequency divider of 1. */ CS_initClockSignal( CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 ); /* Set MCLK = DCO with frequency divider of 1. */ CS_initClockSignal( CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 ); /* Start XT1 with no time out. */ CS_turnOnLFXT( CS_LFXT_DRIVE_0 ); /* Disable the GPIO power-on default high-impedance mode. */ PMM_unlockLPM5(); }
__interrupt void USCI_A1_ISR (void) { GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN3 ); /*make it HIGH because we are processing data*/ uint8_t received_byte = 0x00; static uint8_t rx_buffer[10] = {0x00}; static uint8_t index = 0; switch (__even_in_range(UCA1IV,4)) { //Vector 2 - RXIFG case 2: // received_byte = USCI_UART_receiveData(USCI_A1_BASE); // if(index<sizeof(rx_buffer)) // { // rx_buffer[index] = received_byte; // index++; //} //else // { //} received_byte = USCI_UART_receiveData(USCI_A1_BASE); /*good for debugging. reading the register clears the interupt flag?*/ bt_uart_manager(received_byte); /*pass the byte from the uart into this function which will store it and parse it accordingly*/ break; default: break; } GPIO_setOutputLowOnPin(GPIO_PORT_P4,GPIO_PIN3 ); /*make it low because we are ready to receive data*/ }
void LED::set(const bool is_on) { is_on_ = is_on; isOn() ? GPIO_setOutputHighOnPin(pin_.port, pin_.pin) : GPIO_setOutputLowOnPin(pin_.port, pin_.pin); }