#include <hidef.h>      /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

 void Init(){
    //configurare procesor
    SOPT   = 0x00;	     /* Disable COP	*/
    ICGC2  = 0X00;       // Set up ICG control register 2
    ICGC1  = 0X78;       // Set up ICG for FEE, 4MHz external crystal, busclk = 8MHz
    
	//asteptare pornire FLL (LOCK = 1)
    while(!(ICGS1 & 0x08));
    
	// configurare PORT F
    PTFDD = 0xFF;	     // set port F as outputs for LED operation
  
    //configurare timer 1
    TPM1SC   = 0x4F;
    TPM1MODH = 0xFF;	
    TPM1MODL = 0xFF; 
 }

//rutina intrerupere Timer 1
interrupt 11 void TPM1_timerInt()
{
    byte  varTOF;
   
    varTOF = TPM1SC;	// clear TOF; first read and then write 0 to the flag
    TPM1SC &= 0x7F;
   
    PTFD = ~PTFD;
} 

void main(void) {

  Init();
  EnableInterrupts; /* enable interrupts */
  /* include your code here */

  PTFD = 0xAA;

  for(;;) {
   
  } /* loop forever */
  /* please make sure that you never leave main */
}
