Hi
To get familiar with A/D conversion on a Pic 16f877A. I have done a simple program to test the conversion process.
I'M using internal clock reference and only input AN0. Crystal is 10MHz.
The problem is that according to my code the conversion should be perform only once and than send that conversion to PORTB. but in fact as soon as I change the voltage at the input AN0 the PORTB get updated with a new conversion.
Please can somebody tell me what I did wrong?
Here's my code
void adc_init (void)
{
ADCON0=0x41; // AN0 noGO et power on fosc/16
ADCON1=0x4E; //
//ADIF=0;
//ADIE=1;
//PEIE=1;
//GIE=1;
Delay(300);
}
unsigned char adc_get (void)
{
ADGO=1; // enable conversion A/D AN0
Delay(300);
return ADRESH; // Return the result of the conversion
}
void main(void)
{
unsigned char Conversion;
ADCON0=0x01;
ADCON1=0x46;
TRISA=0x01;
TRISB=0x00;
adc_init(); //set the control of A/D
Conversion=(adc_get()); // Make the conversion store it in Conversion
PORTB=Conversion; // PORTB take the state of conversion
}
To get familiar with A/D conversion on a Pic 16f877A. I have done a simple program to test the conversion process.
I'M using internal clock reference and only input AN0. Crystal is 10MHz.
The problem is that according to my code the conversion should be perform only once and than send that conversion to PORTB. but in fact as soon as I change the voltage at the input AN0 the PORTB get updated with a new conversion.
Please can somebody tell me what I did wrong?
Here's my code
void adc_init (void)
{
ADCON0=0x41; // AN0 noGO et power on fosc/16
ADCON1=0x4E; //
//ADIF=0;
//ADIE=1;
//PEIE=1;
//GIE=1;
Delay(300);
}
unsigned char adc_get (void)
{
ADGO=1; // enable conversion A/D AN0
Delay(300);
return ADRESH; // Return the result of the conversion
}
void main(void)
{
unsigned char Conversion;
ADCON0=0x01;
ADCON1=0x46;
TRISA=0x01;
TRISB=0x00;
adc_init(); //set the control of A/D
Conversion=(adc_get()); // Make the conversion store it in Conversion
PORTB=Conversion; // PORTB take the state of conversion
}