#include "main.h"

#define LED1         PIN_E0  
#define LED2         PIN_E1  
#define SYNC_OUTPUT  PIN_E2  

int1 sync;
int8 sec;

#int_EXT
void  EXT_isr(void) 
{
   if (sync==1) 
   {
      output_high(SYNC_OUTPUT);
      output_toggle(LED2);
      delay_us(2);
      output_low(SYNC_OUTPUT);
      sync=0;
   }
}




void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_31250|OSC_PLL_OFF);

   sync=0;
    //Example blinking LED program
    while(true)
    {
      while (getch()!='$');
      if (getch()!='G') continue;
      if (getch()!='P') continue;
      if (getch()!='R') continue;
      if (getch()!='M') continue;
      if (getch()!='C') continue;
      if (getch()!=',') continue;
      getch();
      getch();
      getch();
      getch();
      getch();
      output_toggle(LED1);
      sec=getch();
      if ((sec!='9')) continue;
      sync=1;
    }

}