maria258
Member level 2
I have already done an 8 bit mode adc but would like to change it to 10 bit. How can this code be altered to make it a 10 bit?
thanks
maria
thanks
maria
Code:
#include<htc.h>
__CONFIG (0x3F72); //configured fuses
//define ports for easier reading
#define LEDS PORTB
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
TRISA=0xFF; //inputs
LEDS=0xFF; //clear/switch off LEDS
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=~z; //output on leds
}
}
void delay(unsigned char itime)
{
unsigned char i,j;
for(i=0;i<itime;i++)
for(j=0;j<1;j++);
}