void main() { WDTCTL = WDTPW + WDTHOLD; //Stop Watchdog Timer CSCTL0_H = 0xA5; CSCTL1 |= DCOFSEL0 + DCOFSEL1; //set max. DCO setting.. 8Mhz CSCTL2 = SELA_3 + SELS_3 + SELM_3; //set ACLK = MCLK = DCO CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0; //set all dividers P1DIR |= BIT0; P1SEL0 |= BIT0; TA0CCR0 = 207; //timer count value 207 for 38 kHz carrier. TA0CCR1 = 69; //25% duty cycle for the 38 kHz carrier. //TA0CCTL1 = OUTMOD_7; TA0CCTL0 = 0x10; TA0CTL = TASSEL_1 + MC_1; LEDonboardInit(0); AccelInit(); //Setup the accelerometer pins. SetupAccel(); //Setup the ADC and Accel. ADC can only convert one axis at a time. CalibrateADC(); //Find zero points of all 3 axis. ADC10CTL0 |= ADC10ENC | ADC10SC; //Start the first sample. If this is not done the ADC10 interupt will not trigger. __enable_interrupt(); while(1) { TA0CTL |= MC_1; ADC10IE &= ~ADC10IE0; LED_off_all(); if (ADCResult_X < CalValue_X - 60 && ADCResult_Y > CalValue_Y - 60 && ADCResult_Y < CalValue_Y + 60) { LED_off_all(); LED_on(8); transmit_command(0x04, 0x01); } else if(ADCResult_X > CalValue_X + 60 && ADCResult_Y > CalValue_Y - 60 && ADCResult_Y < CalValue_Y + 60) {LED_off_all(); LED_on(7); transmit_command(0x04, 0x00); } else if(ADCResult_Y < CalValue_Y - 60 && ADCResult_X > CalValue_X - 60 && ADCResult_X < CalValue_X + 60) { LED_off_all(); LED_on(2); transmit_command(0x04, 0x03); } else if (ADCResult_Y > CalValue_Y + 60 && ADCResult_X > CalValue_X - 60 && ADCResult_X < CalValue_X + 60) { LED_off_all(); LED_on(1); transmit_command(0x04, 0x02); } TA0CTL = TASSEL_1 + MC_0; //timer off TA0CCTL1 = OUTMOD_0; //avoid constant high //__delay_cycles(500000); ADC10IE |= ADC10IE0; //ADC10IE &= ~ADC10IE0; } /* while(1) { transmit_command(0x04, 0x00); } */ }
void Mode3(void) { // One time initialization of header and footer transmit package TX_Buffer[0] = 0xFA; TX_Buffer[6] = 0xFE; // variable initialization active = 1; ADCTemp = 0; temp = 0; WriteCounter = 0; ULPBreakSync = 0; counter = 0; // One time setup and calibration SetupAccel(); CalValue = CalibrateADC(); while ((mode == ACCEL_MEAS) && (UserInput == 0)) { // Take 1 ADC Sample TakeADCMeas(); if (ADCResult >= CalValue) { temp = DOWN; ADCTemp = ADCResult - CalValue; } else { temp = UP; ADCTemp = CalValue - ADCResult; } if((ULP==1) && (UserInput == 0)) { // P3.4- P3.7 are set as output, low P3OUT &= ~(BIT4 + BIT5 + BIT6 + BIT7); P3DIR |= BIT4 + BIT5 + BIT6 + BIT7; // PJ.0,1,2,3 are set as output, low PJOUT &= ~(BIT0 + BIT1 + BIT2 + BIT3); PJDIR |= BIT0 + BIT1 + BIT2 + BIT3; // Transmit break packet for GUI freeze if(!(ULPBreakSync)) { TXBreak(mode); ULPBreakSync++; } } if((ULP==0) && (UserInput == 0)) { ULPBreakSync = 0; WriteCounter++; if(WriteCounter > 300) { LEDSequence(ADCTemp,temp); // Every 300 samples // Transmit 7 Bytes // Prepare mode-specific data // Standard header and footer WriteCounter = 0; TX_Buffer[1] = 0x03; TX_Buffer[2] = counter; TX_Buffer[3] = 0x00; TX_Buffer[4] = 0x00; TX_Buffer[5] = 0x00; TXData(); } } } // end while() loop // turn off Accelerometer for low power ShutDownAccel(); }