#include<pic.h>
//__CONFIG (0x3F72); //configured fuses
//define ports for easier reading
#define LEDS_8 PORTB
#define LEDS_2 PORTC
void delay(unsigned char itime);
void main(void)
{
//8bit data-type variables
unsigned char x; //ADC low byte
unsigned char y; //ADC high byte
unsigned int z; //final result
TRISB=0x00; //output
TRISC=0b00111111;
TRISA=0xFF; //inputs
LEDS_8=0xFF; //clear/switch off LEDS
LEDS_2=0xFF;
while(1)
{
//ADFM=1, all i/ps analog, +VREF enabled
//Configure the functions of the Port bits
ADCON1=0b10000001;
//clock/channel select & enable bits
//controls the operation of the A/D module
ADCON0=0b11000001;
delay(1);
//Start a2d conversion
//Set GO bit (ADCON0=ADCON0|1;)
GODONE=1;
//wait end-of-conversion (conversion complete)
while(GODONE==1);
x=ADRESL; //store low byte
x=x>>1; //shift 1 bit to the right
y=ADRESH; //store high byte
y=y<<7; //shift left 7 bit position
z=x|y; //combine together
LEDS_8=~z;
}
}
void delay(unsigned char itime)
{
unsigned char i,j;
for(i=0;i<itime;i++)
for(j=0;j<1;j++);
}