Esempio n. 1
0
void ConfigureButtons(struct Button *leftButton, struct Button *rightButton, struct Button *upButton, struct Button *downButton)
{
    InitializeButton(leftButton);
    leftButton->GPIOButtonPin = BUTTON_LEFT;
    leftButton->ButtonPressedAction = PrintPreviousImage;

    InitializeButton(rightButton);
    rightButton->GPIOButtonPin = BUTTON_RIGHT;
    rightButton->ButtonPressedAction = PrintNextImage;
}
Esempio n. 2
0
File: main.c Progetto: linkinlzm/MCU
int main(void)
{
    WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer

    initializeClocks();
    InitializeButton();
    InitializeLeds();

    //This will reset the nRF8001. ACI Device Started Event is generated by the nRF8001 device
    //as soon as the reset is complete
    hal_aci_tl_init();

    // Reset nRF8001
    resetDevice();
    _BIS_SR(GIE);

    begin_BLE(&aci_state);

    // Main application loop
    for (;;)
    {
        //_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/interrupt
        _nop();                   // For debugger
        //Not entirely sure if any of this if statement needs to be here...
        if(rdynFlag == 1)
        {
            rdynFlag = 0;

            m_rdy_line_handle();
        }
        pollACI(&aci_state, &aci_data, &aci_cmd);
        state = getState();
        if ((getState() == ACI_EVT_CONNECTED) && (!ctr) && lib_aci_is_pipe_available(&aci_state, PIPE_UART_OVER_BTLE_UART_TX_TX)) {
            //make sure pipe is available
//#define UART
#ifdef UART
            write("80 98 37 998", 12, &aci_state, &aci_data, &aci_cmd);
#else
            write(data, 6, &aci_state, &aci_data, &aci_cmd);
#endif
            //lib_aci_get_battery_level();
        }
        ctr++;
    }
}
Esempio n. 3
0
int main(void)
{
  WDTCTL = WDTPW | WDTHOLD; // Must stop WDT
  InitializeClock();
  InitializeLeds();
  InitializeButton();
  speed = 12000;
  eint();       // same as _BIS_SR(GIE);

  while(1) {
    delay(60000);
    LED_OUT |= LED2;
    delay(3000);
    LED_OUT &= ~LED2;
  }

  return 0;
}
Esempio n. 4
0
void main (void){
	unsigned int uartUpdateTimer = UART_UPDATE_INTERVAL;

	unsigned int servo_stepval, servo_stepnow;
	unsigned int servo_lut[ SERVO_STEPS+1 ];
	unsigned int i;

	// Calculate the step value and define the current step, defaults to minimum.
	servo_stepval 	= ( (SERVO_MAX - SERVO_MIN) / SERVO_STEPS );
	servo_stepnow	= SERVO_MIN;

	// Fill up the LUT
	for (i = 0; i > SERVO_STEPS; i++) {
		servo_stepnow += servo_stepval;
		servo_lut[i] = servo_stepnow;
		//pulseWidth = (myAngle * 11) + 500;  // конвертируем угол в микросекунды
	}
	TA1CCR1 = 0;
	// Setup the PWM, etc.
	WDTCTL	= WDTPW + WDTHOLD;     // Kill watchdog timer
	TACCTL1	= OUTMOD_7;            // TACCR1 reset/set
	TACTL	= TASSEL_2 + MC_1;     // SMCLK, upmode
	TACCR0	= PWM_Period-1;        // PWM Period
	TACCR1	= PWM_Duty;            // TACCR1 PWM Duty Cycle
	P1DIR	|= BIT2;               // P1.2 = output
	P1SEL	|= BIT2;               // P1.2 = TA1 output
	P2SEL2	|= BIT2;               // P1.2 = TA1 output

	InitializeClocks();
	InitializeButton();
	InitializeLeds();
	PreApplicationMode();         // Blinks LEDs, waits for button press

	/* Application Mode begins */
	applicationMode = APP_APPLICATION_MODE;

	__enable_interrupt();                     // Enable interrupts.

	while(1)
	{
		__bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled

	    if ((--uartUpdateTimer == 0) || calibrateUpdate )
	    {
	      ConfigureTimerUart();
	      if (calibrateUpdate)
	      {
	        TXByte = 248;                       // A character with high value, outside of temp range
	        Transmit();
	        calibrateUpdate = 0;
	      }
	      TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );

	      Transmit();

	      uartUpdateTimer = UART_UPDATE_INTERVAL;
	      ConfigureTimerPwm();
	    }
	}
/*
	TACCR1 = SERVO_MAX; //180°
	__delay_cycles(1000000);
	TACCR1 = 1600; //90°
	__delay_cycles(1000000);
	TACCR1 = SERVO_MIN; //0°
*/
	// Main loop
//	while (1){
		// Go to 0°
//		TACCR1 = servo_lut[0];
//		__delay_cycles(1000000);

		// Go to 45°
//		TACCR1 = servo_lut[45];
//		__delay_cycles(1000000);

		// Go to 90°
//		TACCR1 = servo_lut[90];
//		__delay_cycles(1000000);

		// Go to 180°
//		TACCR1 = servo_lut[179];
//		__delay_cycles(1000000);
/*
		// Move forward toward the maximum step value
		for (i = 0; i > SERVO_STEPS; i++) {
			TACCR1 = servo_lut[i];
			__delay_cycles(20000);
		}

		// Move backward toward the minimum step value
		for (i = SERVO_STEPS; i > 0; i--) {
			TACCR1 = servo_lut[i];
			__delay_cycles(20000);
		}
*/
 //  }
}
Esempio n. 5
0
void main(void)
{
  unsigned int uartUpdateTimer = UART_UPDATE_INTERVAL;
  unsigned char i;

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  InitializeClocks();
  InitializeButton();
  InitializeLeds();
  PreApplicationMode();                     // Blinks LEDs, waits for button press
  
  /* Application Mode begins */
  applicationMode = APP_APPLICATION_MODE;
  ConfigureAdcTempSensor();
  ConfigureTimerPwm();
    
  __enable_interrupt();                     // Enable interrupts.
  
  /* Main Application Loop */
  while(1)
  {    
    ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled
    
    
    /* Moving average filter out of 8 values to somewhat stabilize sampled ADC */
    tempMeasured[tempMeasuredPosition++] = ADC10MEM;
    if (tempMeasuredPosition == 8)
      tempMeasuredPosition = 0;
    tempAverage = 0;
    for (i = 0; i < 8; i++)
      tempAverage += tempMeasured[i];
    tempAverage >>= 3;                      // Divide by 8 to get average
    
    if ((--uartUpdateTimer == 0) || calibrateUpdate )
    {
      ConfigureTimerUart();
      if (calibrateUpdate)
      { 
        TXByte = 248;                       // A character with high value, outside of temp range 
        Transmit();
        calibrateUpdate = 0;
      }   
      TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );   
         
      Transmit(); 
      
      uartUpdateTimer = UART_UPDATE_INTERVAL;
      ConfigureTimerPwm();      
    }
    
    tempDifference = tempAverage - tempCalibrated;
    if (tempDifference < -TEMP_THRESHOLD)
    {
      tempDifference = -tempDifference;
      tempPolarity = TEMP_COLD;
      LED_OUT &= ~ LED1;
    }
    else
    if (tempDifference > TEMP_THRESHOLD)
    {
      tempPolarity = TEMP_HOT;
      LED_OUT &= ~ LED2;
    }
    else
    {
      tempPolarity = TEMP_SAME;
      TACCTL0 &= ~CCIE;
      TACCTL1 &= ~CCIE;
      LED_OUT &= ~(LED1 + LED2);        
    } 
    
    if (tempPolarity != TEMP_SAME)    
    {      
      tempDifference <<= 3;
      tempDifference += TIMER_PWM_OFFSET;      
      TACCR1 = ( (tempDifference) < (TIMER_PWM_PERIOD-1) ? (tempDifference) : (TIMER_PWM_PERIOD-1) );
      TACCTL0 |= CCIE;
      TACCTL1 |= CCIE;      
    }   
  }  
}