#include <18F2550.h>
#device adc=10

#FUSES WDT4                     //Watch Dog Timer uses 1:4 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOMCLR                 //Master Clear pin disabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1                     //No PLL PreScaler

#use delay(clock=8000000,restart_wdt)

#byte       PORTA=      0xF80
#byte       PORTB=      0xF81
#byte       PORTC=      0xF82
#byte       PORTE=      0xF84

#bit        PULS1=      PORTC.0     // Pulsador Marrón
#bit        PULS2=      PORTA.6     // Pulsador verde

#define use_portb_lcd TRUE
//#include <LCD.C>

int16 i,j;

void main()
{
   setup_adc_ports(AN0_TO_AN4|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_spi(FALSE);
   setup_wdt(WDT_ON);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_4,255,1);

   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   setup_low_volt_detect(FALSE);


   i=800;   // punto medio del duty de 10 bits
   setup_ccp1(CCP_PWM);
   set_pwm1_duty(i);
   set_adc_channel(0);
   while (1) {
      set_pwm1_duty(i);
      i = read_adc();7
      delay_ms(10);
   }

}
