Exemplo 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
}
unsigned char button_is_active(unsigned char button_nr)
{
    switch (button_nr)
    {
        case 1:
            return (GPIO_INPUT_PIN_LOW == GPIO_getInputPinValue(INPUT1_BASEADDRESS, INPUT1_PORT, INPUT1_PIN));
        case 2:
            return (GPIO_INPUT_PIN_LOW == GPIO_getInputPinValue(INPUT2_BASEADDRESS, INPUT2_PORT, INPUT2_PIN));
        case 3:
            return (GPIO_INPUT_PIN_LOW == GPIO_getInputPinValue(INPUT3_BASEADDRESS, INPUT3_PORT, INPUT3_PIN));
        default:
        	return false;
    }

}
Exemplo n.º 3
0
int ti_button_2_pressed()
{
    if (GPIO_getInputPinValue(GPIO_PORT_P6, GPIO_PIN1) == GPIO_INPUT_PIN_LOW)
        return 1;
    else
        return 0;
}
Exemplo n.º 4
0
int sensorhub_button_1_pressed()
{
	if (GPIO_getInputPinValue(GPIO_PORT_P6, GPIO_PIN3) == GPIO_INPUT_PIN_LOW)
		return 1;
	else
		return 0;
}
Exemplo n.º 5
0
int launchpad_button_1_pressed()
{
	if (GPIO_getInputPinValue(GPIO_PORT_P2, GPIO_PIN1) == GPIO_INPUT_PIN_LOW)
		return 1;
	else
		return 0;
}
Exemplo n.º 6
0
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 );
          }
      }
  }
Exemplo n.º 7
0
int main(void)
{
  //Default MCLK = 1MHz
  
  unsigned int i = 0;
  unsigned char dialValue = 0x01;
  WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer

  initialiseLedDial();
  
  // Disable the GPIO power-on default high-impedance mode
  // to activate previously configured port settings
  PMM_unlockLPM5();
  
  unsigned int S,j,k=1;
  //S=1;
  while(1)
  {
    S=GPIO_getInputPinValue(GPIO_PORT_P1,GPIO_PIN3);
    if(S==0)
      k=-k;
      //dialValue = dialValue * 0x02;
      
      //if(0x00 == dialValue)
        // dialValue = 0x01;
    
    //Set value
      if(k==1)
      {  
        for(j=0;j<8;j++)
        {
          setLedDial(dialValue);
          dialValue=dialValue<<1;
        //Refresh display (10 times for each position)
        for(i = 0; i < 10; i++)
          refreshLedDial();
        }
        dialValue = 0x01;
      }
      else
      {
        dialValue=0x80;
        for(j=0;j<8;j++)
        {
          setLedDial(dialValue);
          dialValue=dialValue>>1;
        //Refresh display (10 times for each position)
        for(i = 0; i < 10; i++)
          refreshLedDial();
       }
       dialValue = 0x01;
      }
  }
}
Exemplo n.º 8
0
/*
 * Read GPIO value
 */
unsigned short int readGpio() {
	unsigned short int value = 0;
	GPIO_setAsInputPinWithPullDownResistor(RULE_PORT, RULE_READ_PIN);
	value = GPIO_getInputPinValue(RULE_PORT, RULE_READ_PIN);

	/*
	 P1DIR |= 0x00;
	 P1REN |= 0x80;
	 P1OUT &= 0x00; -- pull down
	 value = P1HN & 0x80;
	 */
	return value;
}
Exemplo n.º 9
0
__interrupt void Port_2 (void)
{
    __delay_cycles(10000);   //1234us at 8MHz
    if (GPIO_INPUT_PIN_LOW == GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN4)){
         __delay_cycles(10);
    }else{
         __delay_cycles(10);
    }

    //Pin IFG cleared
    GPIO_clearInterruptFlag(
        GPIO_PORT_P2,
        GPIO_PIN4
        );
}
/*
@@********************* CYC_SYS_UART_TransmitData(UINT8 *rpu8Data, UINT8 ru8DataLen) ***************************************
 *  Function	     :
 *  Description 	 :
 *  Input parameters :
 *  Output parameters:
 *  Return      	 :
 *  Note         	 :
 ******************************************************************************
 */
uint8_t CYC_SYS_UART_TransmitData(UINT8 port, UINT8 *rpu8Data, UINT8 ru8DataLen)
{
	int portBase;
	uint8_t flow_control = 0;

	switch (port) {
	case 0:
		portBase = USCI_A0_BASE;
		break;
	case 1:
		portBase = USCI_A1_BASE;
		flow_control = 1;
		break;
	default:
		return !SUCCESS;
	}

	uint8_t	lsReturnValue = SUCCESS;

	UINT8 lu8TxBufferLen = 0;

	for(lu8TxBufferLen = 0; lu8TxBufferLen < ru8DataLen; lu8TxBufferLen++)
	{


	    if(flow_control == 1)
	    {
	        while( GPIO_getInputPinValue(GPIO_PORT_P4, GPIO_PIN0) == 1)
	            {
	                /*this pin is high when bluetooth is not ready to receive data*/
	            }
	    }
	    else
	    {
	        /*dont have to wait for pin to go low*/
	    }


	    USCI_UART_transmitData(portBase,rpu8Data[lu8TxBufferLen]);

		//	Keep looping until the BUSY FLAG is set
		while(USCI_UART_queryStatusFlags(portBase,USCI_UART_BUSY));

	}

	return lsReturnValue;
}
Exemplo n.º 11
0
void main (void)
{
    //Stop watchdog timer
    WDT_hold(__MSP430_BASEADDRESS_WDT_A__);

    //If clock signal from master stays low, it is not yet in SPI mode
    while ( GPIO_INPUT_PIN_LOW ==
            GPIO_getInputPinValue(__MSP430_BASEADDRESS_PORT3_R__,
                GPIO_PORT_P3,
                GPIO_PIN0
                )) ;

    //P3.5,4,0 option select
    GPIO_setAsPeripheralModuleFunctionInputPin(__MSP430_BASEADDRESS_PORT3_R__,
        GPIO_PORT_P3,
        GPIO_PIN0 + GPIO_PIN4 + GPIO_PIN5
        );

    //Initialize slave to MSB first, inactive high clock polarity and 3 wire SPI
    returnValue = SPI_slaveInit(__MSP430_BASEADDRESS_USCI_A0__,
        SPI_MSB_FIRST,
        SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT,
        SPI_CLOCKPOLARITY_INACTIVITY_HIGH
        );

    if (STATUS_FAIL == returnValue){
        return;
    }

    //Enable SPI Module
    SPI_enable(__MSP430_BASEADDRESS_USCI_A0__);

    //Enable Receive interrupt
    SPI_enableInterrupt(__MSP430_BASEADDRESS_USCI_A0__,
        SPI_RECEIVE_INTERRUPT
        );

    //Enter LPM4, enable interrupts
    __bis_SR_register(LPM4_bits + GIE);
}
Exemplo n.º 12
0
Arquivo: main.c Projeto: ctag/cpe495
int getRight()
{
	if (GPIO_getInputPinValue(RIGHT_BUTTONS_PORT, GPIO_PIN0))
		return 0;
	if (GPIO_getInputPinValue(RIGHT_BUTTONS_PORT, GPIO_PIN1))
		return 1;
	if (GPIO_getInputPinValue(RIGHT_BUTTONS_PORT, GPIO_PIN2))
		return 2;
	if (GPIO_getInputPinValue(RIGHT_BUTTONS_PORT, GPIO_PIN3))
		return 3;
	if (GPIO_getInputPinValue(RIGHT_BUTTONS_PORT, GPIO_PIN4))
		return 4;
	if (GPIO_getInputPinValue(RIGHT_BUTTONS_PORT, GPIO_PIN5))
		return 5;
	else
		return -1;
}
Exemplo n.º 13
0
Arquivo: main.c Projeto: ctag/cpe495
int getLeft()
{
	if (GPIO_getInputPinValue(LEFT_BUTTONS_PORT, GPIO_PIN0))
		return 0;
	else if (GPIO_getInputPinValue(LEFT_BUTTONS_PORT, GPIO_PIN2))
		return 1;
	else if (GPIO_getInputPinValue(LEFT_BUTTONS_PORT, GPIO_PIN3))
		return 2;
	else if (GPIO_getInputPinValue(LEFT_BUTTONS_PORT, GPIO_PIN4))
		return 3;
	else if (GPIO_getInputPinValue(LEFT_BUTTONS_PORT, GPIO_PIN5))
		return 4;
	else if (GPIO_getInputPinValue(LEFT_BUTTONS_PORT, GPIO_PIN6))
		return 5;
	else
		return -1;
}
__LINK_C bool hw_gpio_get_in(pin_id_t pin_id)
{
    // TODO check if pin configured?
    // TODO not tested yet
    return GPIO_getInputPinValue(pin_id.port, pin_id.pin) == GPIO_INPUT_PIN_HIGH;
}