Hi I found out that code in the forum but it didnt work for me :\ Is there something wrong with the code or connections?(Btw I am using msp430g2553 ) #include #define smclk 1000000 #define servo_freq 50 char debounce = 25; // not zero as we need it as a init int pwm_period = smclk /servo_freq; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer if (CALBC1_1MHZ != 0xff){ // don't use if erased BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation } P1DIR &= ~(BIT3 + BIT4 + BIT5); // set 3-4-5 input (a PUC does that) P1REN |= (BIT3 + BIT4 + BIT5); // 3-4-5 pull resistor enable P1OUT |= (BIT3 + BIT4 + BIT5); // 3-4-5 pull-up direction P1IES |= (BIT3 + BIT4 + BIT5); // high-to-low edge interrupt P2DIR |= BIT2; // P2.2 output; P2SEL |= BIT2; // set timer TA.1 TA1CCR0 = pwm_period-1; // Set Timer_A1 period to TA1CCTL1 = OUTMOD_7; // CCR1 reset/set TA1CCR1 = 1000; // CCR1 PWM duty cycle TA1CTL = TASSEL_2 + MC_1; // smclock - upmdode TA1CCTL0 = CCIE; // interrupt enable while(1) { _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } } //╞════════════════════════════ TA1 ISR ══════════════════════════════════════╡ #pragma vector=TIMER1_A0_VECTOR // Timer A1_0 interrupt service routine __interrupt void Timer_A1 (void) { if (debounce && !(--debounce)){ // good rule is not to pre-decrement P1IFG &= ~(BIT3 + BIT4 + BIT5); // without checking if already zero P1IE |= (BIT3 + BIT4 + BIT5); // interrupt enable } } //╞════════════════════════════ P1 ISR ═══════════════════════════════════════╡ #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1IE &= ~(BIT3 + BIT4 + BIT5); // interrupt disable as a debounce debounce = 25; // 25*20ms = 1/2sec lock-out period if (P1IFG & BIT3) TA1CCR1 = 1000; else if (P1IFG & BIT4) TA1CCR1 = 1500; else if (P1IFG & BIT5) TA1CCR1 = 2000; }
↧