Hi, I am trying to rotate a servomotor by pressing two keys on my keyboard "w" and "s", the servo I use is a SG90 and when I press any of the keys what it will do is move one by one to its limit, I achieve do this with the buttons integrated to the card but with the keys I can't do it. I am using RS232 for this.
code:
#include <msp430.h>
int i, deg=310;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
// Servo
P2DIR |= BIT0;
P2SEL |= BIT0;
TA1CTL |= TASSEL_1 + MC_3 +ID_0; // ACLK ---> 32768 Hz, up/down, div/1
TA1CCTL1 = OUTMOD_6;
TA1CCR0 = 327;
TA1CCR1 = deg;
//RS232
P4SEL |= BIT5 + BIT4; // TX, RX
UCA1CTL1 |= UCSWRST;
UCA1CTL1 |= UCSSEL_2;
UCA1BR0 = 9; // RS-232 2400, 4800, 9600, 19200,... 115200 (BS)
UCA1BR1 = 0; // 8 N 1
UCA1MCTL = UCBRS_1 + UCBRF_0;
UCA1CTL1 &= ~UCSWRST;
UCA1IE |= UCRXIE;
__bis_SR_register(LPM0_bits + GIE);
__no_operation();
return 0;
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch (__even_in_range(UCA1IV, 4))
{
case 0: break;
case 1: break;
case 2:
for(i=0x30; i>0; i--){
TA1CCR1 = deg;
while(!(UCA1IFG & UCTXIFG));
UCA1TXBUF = UCA1RXBUF;
if(UCA1TXBUF == 'w'){
deg += 1;
TA1CCR1 = deg;
}
if(UCA1TXBUF == 's'){
deg -= 1;
TA1CCR1 = deg;
}
}
case 3: break;
default: break;
}
}