//
// Timer Example
// By PEK '2004
//
// MCU: 16F877
// Clock: 10 MHz
//
// To be used with the CCS compiler
//

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use fast_io(B)

int cntr = 0;


#INT_CCP1
void compare_isr()
{
   set_timer1(0);

   cntr++;
   
   if(cntr == 5)
   {
      output_high(PIN_B0);
   }
   else if(cntr == 10)
   { 
      output_low(PIN_B0);
      cntr = 0;
   }
}


void main()
{
   output_b(0x00);
   set_tris_b(0xFE);            // Set pin 0 as output

   setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
   CCP_1=31250;                 // Set compare value to 1 sec
   setup_ccp1(CCP_COMPARE_INT);
   set_timer1(0);

   enable_interrupts(INT_CCP1);
   enable_interrupts(GLOBAL);

   while(1);
}

