////////////////////////////// // Function Initializations // ////////////////////////////// void pos_read(void); void move_down(volatile unsigned int, unsigned int); ... /////////////////// // Main Function // /////////////////// volatile unsigned int current_position; int main(void) { volatile unsigned int favorite_position = 200; volatile unsigned int max_position = 575; volatile unsigned int min_position = 68; ... //Rotate motor down function call else if(rf_input_buffer == RF_DOWN){ //Command routine move_down(current_position, min_position); } ... #pragma vector = ADC10_VECTOR __interrupt void ADC_ISR(void) { //ADC channel buffer adc_count--; ... //Save A1, Potentiometer input else if(adc_count == 1){ //Save position current_position = ADC10MEM0; //Enable conversion of next channel ADC10CTL0 |= ADC10SC; } ... else{ //Enable conversion of next channel ADC10CTL0 |= ADC10SC; } } ... ////////////////////////////////// // Position read, move function // ////////////////////////////////// void pos_read(void) { //Enable interrupt ADC10IE = ADC10IE0; //Enable, start conversion ADC10CTL0 |= ADC10ENC + ADC10SC; while(ADC10CTL1 & ADC10BUSY); } void move_down(volatile unsigned int current_position, unsigned int min_position) { //Detect current position pos_read(); //Limit check while(current_position > min_position){ //Drive motor downwards P2OUT_MOTOR &= ~MOTOR_CCW; P2OUT_MOTOR |= MOTOR_CW; //Detect current position pos_read(); } //Stop motor P2OUT_MOTOR &= ~(MOTOR_CW + MOTOR_CCW); //Disable potentiometer P1OUT_POT &= ~POT_EN; }