Kod: Markera allt
int pic_ad_read(unsigned char channel)
{
char i;
int tal;
ADCON0 = 0x01; //reset channels
ADCON0 |= (channel<<2);
for(i=0;i<50;i++);
ADCON0bits.GO = 1; //start the conversion
while(ADCON0bits.GO == 1);
tal = ADRESH;
tal += (tal<<2)+(ADRESL>>6);
return(tal);
}