
 #include <p18f24k22.h>
 #include "delays.h"
 #include "adc.h"
        
            /* Set up the configuration bits */

  #pragma config FOSC = HSMP  
  #pragma config FOSC = INTIO67    
  #pragma config PLLCFG = ON
  #pragma config PRICLKEN = ON
  #pragma config IESO = OFF
  #pragma config PWRTEN = OFF
  #pragma config BOREN = OFF
  #pragma config WDTEN = OFF
  #pragma config PBADEN = ON
  #pragma config CP0 = OFF
  #pragma config CP1 = OFF
  #pragma config CPB = OFF
  #pragma config CPD = OFF
  
 //  ? #use delay(clock=16000000)     // belso kvarc 16MHz hajtva
 
/* void ConvertADC (void){}
    #if defined (ADC_V1)
	
		 #define ADC_8ANA_0REF    0b00000000				// VREF+=VDD,VREF-=VSS: all analog channels   (8 analog channels/0 Voltage Reference)
 
    #ifndef	USE_OR_MASKS	
 #define ADC_FOSC_2       0b10001111 			//A/D conversion clock source is Fosc/2
 //#define ADC_6ANA_0REF    0b00001001 			// VREF+=VDD,VREF-=VSS:  DIG- AN7,6 : ANG- AN5,4,3,2,1,0  (6 analog channels/0 Voltage Reference)
#define ADC_8ANA_0REF    0b00000000				// VREF+=VDD,VREF-=VSS: all analog channels   (8 analog channels/0 Voltage Reference)
#define ADC_REF_VDD_VSS 	0b11111100 	       // ADC voltage source VREF- = AVSS 
 
 #define ENABLE_AN0_ANA()              ANCON0bits.PCFG0=0 //Enable AN0 in analog mode 
 #define ENABLE_AN1_ANA()              ANCON0bits.PCFG1=0 //Enable AN1 in analog mode 
 #define ENABLE_AN2_ANA()              ANCON0bits.PCFG2=0 //Enable AN2 in analog mode 
 #define ENABLE_AN3_ANA()              ANCON0bits.PCFG3=0 //Enable AN3 in analog mode 
 #define ENABLE_AN8_ANA()              ANCON1bits.PCFG8=0 //Enable AN8 in analog mode 
 #define ENABLE_AN9_ANA()              ANCON1bits.PCFG9=0 //Enable AN9 in analog mode 
 #define ENABLE_AN10_ANA()             ANCON1bits.PCFG10=0 //Enable AN10 in analog mode 
 #define ENABLE_AN11_ANA()             ANCON1bits.PCFG11=0 //Enable AN11 in analog mode 
 
 #endif // USE_OR_MASKS
#ifndef USE_OR_MASKS
//**************** channel selection ******************************************
#define ADC_CH0          0b10000011  			//Select Channel 0
#define ADC_CH1          0b10000111  			//Select Channel 1
#define ADC_CH2          0b10001011  			//Select Channel 2
#define ADC_CH3          0b10001111  			//Select Channel 3
#define ADC_CH4          0b10010011  			//Select Channel 4
#if defined (ADC_V13) || defined (ADC_V13_1)  || defined (ADC_V13_3)
#define ADC_CH5          0b10010111  			//Select Channel 5
#define ADC_CH6          0b10011011  			//Select Channel 6
#define ADC_CH7          0b10011111  			//Select Channel 7
#define ADC_CH8          0b10100011  			//Select Channel 8

#endif
 #endif  
 #endif
 }*/
	 void ConvertADC(void){
     CONFIG_AN0_AS_ANALOG();                                  
     CONFIG_AN1_AS_ANALOG();      //AN1(RA1) analóg bemenet beállítása
     CONFIG_AN2_AS_ANALOG(); 
     CONFIG_AN3_AS_ANALOG();        
     CONFIG_AN8_AS_ANALOG();       
     CONFIG_AN9_AS_ANALOG();        
     CONFIG_AN10_AS_ANALOG();       
     CONFIG_AN11_AS_ANALOG();      
          	ADCON0=0x28;                    // ADC még letiltva
     ADCON1=0;                       //VREF+ = VDD, VREF- = VSS
     
     ADCON0bits.ADON=1;              //Az ADC engedélyezése
 }
/*    void ConvertADC (config){
        CONFIG_ADC_FOSC 2 FOSC/2
         }*/
         
         
         
 int osszeg(int a, int b, int c,int d, int e, int f, int g, int h){
		a = 1 if AN0 = 1
		b=2 if an1=1
		c=4 if an2=1
		d=8 if an3=1
		e=16 if an8=1
		f=32 if an9=1
		g=64 if an10=1
		h=128 if an11=1
	int s=a+b+c+d+e+f+g+h;
return s; 
}




