papunblg
Advanced Member level 3
- Joined
- Oct 22, 2010
- Messages
- 716
- Helped
- 172
- Reputation
- 344
- Reaction score
- 165
- Trophy points
- 1,343
- Location
- Kolkata India
- Activity points
- 6,421
The following code (to measure voltage using inbuilt ADC) is not working as expected. It appears that AN0 is not accepting input. Am I missing something? (for the time being I am using ADC0804 with 16f876A!!!!!!!!!as I am pretty comfortable with it)
void main(void)
{
ADCON0=0b10000000;
ADCON1=0b11000000;
ADCON0.ADON=1; // turn on the A2D conversion module
Delay_ms(300);
LCD_init();
while(1){
Delay_ms(300);
read_adc();
-----
-------
}
void read_adc(void)
{
unsigned short result;
ADCON0.GO = 1; //ADC start
while(ADCON0.GO==1);
result=ADRESH;
result=result<<8; //shift to left for 8 bit
result=result|ADRESL; //10 bit result from ADC
}
void main(void)
{
ADCON0=0b10000000;
ADCON1=0b11000000;
ADCON0.ADON=1; // turn on the A2D conversion module
Delay_ms(300);
LCD_init();
while(1){
Delay_ms(300);
read_adc();
-----
-------
}
void read_adc(void)
{
unsigned short result;
ADCON0.GO = 1; //ADC start
while(ADCON0.GO==1);
result=ADRESH;
result=result<<8; //shift to left for 8 bit
result=result|ADRESL; //10 bit result from ADC
}