
#include "RF04EB.h"
#include "hal.h"
#include "cul.h"

WORD BRUSHLESS1, BRUSHLESS2;
BOOL fBrushless;

#pragma vector=T1_VECTOR
__interrupt void T1_Interrupt_handler(void){
  if (fBrushless) {
    halSetTimer1Period(BRUSHLESS1);
    fBrushless = FALSE;
    P1_3 = 1;
  }
  else {
    halSetTimer1Period(BRUSHLESS2);
    fBrushless = TRUE;
    P1_3 = 0;
  };
}

void main(void)
{
  SET_MAIN_CLOCK_SOURCE(CRYSTAL);
  INT_GLOBAL_ENABLE(INT_ON);              // Global Interrupt enabled
  INT_ENABLE(INUM_T1, INT_ON);            // Interrupt TIMER1 enabled
  
  //TIMER1_INIT();
  T1CTL = 0x02;
  T1CCTL0 = 0x44; //***** THIS IS THE STRANGE PART!!!
  T1CCTL1 = 0x00;
  T1CCTL2 = 0x00;
  TIMIF &= ~0x40;

  TIMER1_ENABLE_OVERFLOW_INT(TRUE);       // TIMER1 Overflow Mask

  BRUSHLESS1 = 1000;
  BRUSHLESS2 = 1000;
  TIMER1_RUN(TRUE);                       // Start TIMER1

  IO_DIR_PORT_PIN(1, 3, IO_OUT); // P1.0 as output
  P1SEL &= ~0x08;                         // general purpose I/O

  //do {
  //} while (1);
