#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;	 
      
    //configurare timer 1
    TPM1SC   = 0x0F;	
    TPM1MODH = 0xFF;	
    TPM1MODL = 0xFF;
}


void main(void) {

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

  PTFD  = 0x00;  
  
  for(;;) {
  
  	while((TPM1SC & 0x80) == 0x00);  //astept sa vina timer-ul
  	TPM1SC &= 0x7F;                  //resetam flag-ul
  
  PTFD = ~PTFD;
    
  } /* loop forever */
  /* please make sure that you never leave main */
}
