/*
 * File:   Main.c
 * Author: topicchi
 *
 * Created on 8 ottobre 2013, 21.00
 */

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>

#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4000000
#endif

#define LED_0 PORTAbits.RA2
#define LED_1 PORTAbits.RA3

//#pragma config FOSC =  EXTRC, WDTE = OFF, PWRTE = ON//, CP = OFF
#pragma config FOSC =  XT, WDTE = OFF, PWRTE = ON//, CP = OFF
#define FOSC 4000000

/*
 *
 */
int main(int argc, char** argv) {
    char outt, dir;
    TRISA=0x00;
    PORTA=0x00;
    TRISB=0x00;
    PORTB=0xFF;
    outt=1;
    dir=1;
    while(1) // Run Forever
    {

      __delay_ms(100);
      PORTB=outt^0xFF;
      if (dir){
          outt*=2;
      }
      else {
          outt/=2;
      };
      if(outt>=0x40){
          dir=0;
          __delay_ms(50);
      }
      if (outt<=1){
          dir=1;
          outt=1;
          __delay_ms(50);
      }

    }


    return (EXIT_SUCCESS);
}

