i am new using microcontrollers. at the moment im starting using 16f877 and need to start by programming the adc (10 bit). all i did for now is the code shown below. is it enough to read data? or does it need alteration?
i am using mplab to compile and proteus for schematics.
thanks
maria
You don't mention what speed your chip will be running at and so the value for Fosc division is unknown. To be safe set it to Fosc/32. You also don't need to combine the registers the way you have it, you can do it like,
Code:
void main(void){
//configuring input/outputs
PORTA = 0x00;
TRISA = 0xFF;
TRISB = 0x00;
//configuring ADC
ADCON0=0b10000001 //setting ADON on and Fosc/32
ADCON1=0b11000000 //ADFM is set right and Fosc/32
while(1){
GODONE=1; //start conversion
while(GODONE); //wait for it to complete
data=ADRESH*256+ADRESL; //get answer
}
}
Note, you have to wait for the conversion to complete.
You will also need to set a config value to use it in an actual chip.
Also, when posting code use the code tags or type [code] before it and [/code] after it.