#include  <msp430x16x.h>
#include  <stdio.h>

char string1[] = {"AT+CIER=1,0,1,0\r"};   // Command to enable service indication reporting
char string2[] = {"AT+SBDWB=5\r"};          // Command to transfer a 5 byte message to 9601-D
char string3[] = {"AT+SBDIX\r"};            // Command to perform SBD session            

unsigned char modem[24];                

char i;
char j = 0;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog
  P3SEL = 0x30;                             // P3.4,5 = USART0 TXD/RXD
  ME1 |= UTXE0 + URXE0;                     // Enabled USART0 TXD/RXD
  UCTL0 |= CHAR;                            // 8-bit character, SWRST=1
  UTCTL0 |= SSEL0;                          // UCLK = ACLK
  
  UBR00 = 0x03;                             // 9600 from 32.768 kHz
//  UBR00 = 0x06;                             // 4800 from 32.768 kHz
//  UBR00 = 0x0D;                             // 2400 from 32.768 kHz
//  UBR00 = 0x1B;                             // 1200 from 32.768 kHz
//  UBR00 = 0x36;                             // 600 from 32.768 kHz
  
  UBR10 = 0x00;                             //
  
  UMCTL0 = 0x4A;                            // Modulation for 9600
//  UMCTL0 = 0x6F;                            // Modulation for 4800
//  UMCTL0 = 0x6B;                            // Modulation for 2400
//  UMCTL0 = 0x03;                            // Modulation for 1200
//  UMCTL0 = 0xB5;                            // Modulation for 600
  
  UCTL0 &= ~SWRST;                          // Initialize USART state machine
  IE1 |= URXIE0;                            // Enable USART0 RX interrupt
  IFG1 &= ~UTXIFG0;                         // Clear inital flag on POR
 
  i = 0;
  while (i < sizeof string1-1)
  {
    while (!(U0TCTL & TXEPT));                // USART0 TX buffer ready?
    TXBUF0 = string1[i++];
 }
 
  while ( j < 17);  

  for (j = 0; j < 17; j++)
  {
    printf ( "%x\n", modem[j]);
  }
  
  printf ("\n");
  
  j = 0;
  i = 0;
  
  while (i < sizeof string2-1)
  {
    while (!(U0TCTL & TXEPT));                // USART0 TX buffer ready?
    TXBUF0 = string2[i++];
  }
  
  while ( j < 9);  
  for (j = 0; j < 9; j++)
  {
    printf ( "%x\n", modem[j]);
  }
  printf ("\n");
  
  i = 0;
  j = 0;
  
  modem[0] = 0;
  modem[1] = 0;
  modem[2] = 0;
  modem[3] = 0;
  modem[4] = 0;
  modem[5] = 0;
 
  while (!(U0TCTL & TXEPT));
  TXBUF0 = 0x68;
  while (!(U0TCTL & TXEPT));
  TXBUF0 = 0x65;
  while (!(U0TCTL & TXEPT));
  TXBUF0 = 0x6C;
  while (!(U0TCTL & TXEPT));
  TXBUF0 = 0x6C;
  while (!(U0TCTL & TXEPT));
  TXBUF0 = 0x6F;
  while (!(U0TCTL & TXEPT));
  TXBUF0 = 0x02;
  while (!(U0TCTL & TXEPT));
  TXBUF0 = 0x14;
  
  while ( j < 10);  
   for (j = 0; j <5 ; j++)
  {
    printf ( "%x\n", modem[j]);
  }
  
  printf ("\n");
  
  i = 0;
  j = 0;
  
  while (i < sizeof string3-1)
  {
    while (!(U0TCTL & TXEPT));                // USART0 TX buffer ready?
    TXBUF0 = string3[i++];
  }
  
   while ( j < 24);  
   for (j = 0; j < 24; j++)
  {
    printf ( "%x\n", modem[j]);
  }
}

// UART0 RX ISR
#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
  modem[j] = RXBUF0;
  j++;
}
