I'm trying to read the ADC of PIC18f4550 and put that value on PORTB. I'm using ADC interrupt so I want to read the value when the ADC triggers an interrupt(conversion is complete).
However I cannot see any change on the leds. They won't light up at all. Please help me correct this issue. I have no ideea what I'm doing wrong. Thanks.
The conventional way of writing your interrupt handler would be -
Code:
if (ADIE && ADIF){
LATB = ADRESL;
}
This ensures it will only invoke the ADC handler if the ADC interrupt is enabled should you decide to expand on your code and add other interrupt sources.
Also, disabling the ADC in the handler will only invoke a sample once instead of providing real time updates. I'd add a 1/4 second delay to the while loop as you don't need to sample every microsecond.
I would also keep the result left justified and read ADRESH only unless you need full 10-bit resolution.