takao21203
- Joined Apr 28, 2012
- 3,702
It is a very bad program.Hi,
Testing ADC code in MP lab is this possible??
Don't know it will work but it is according to data sheet ....
Rich (BB code):#include <htc.h> __CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS); #define _XTAL_FREQ 20000000 #define DAD PORTB main(){ TRISB=0X00; TRISA = 0xff ; ADCON1=0b00000000; ADCON0=0b10000001;//000 = channel 0, (RA0/AN0) while(1){ ADIF=0; ADIE=1; PEIE=1; GIE=1; __delay_ms(1); GO_DONE=1; __delay_ms(1); DAD=ADRESH; } }
1. The initialization is found inside the main loop. Nobody does that.
2. Interrupt is switched on, but no interrupt handler (this was pointed out already).
3. There are unneccessary delays.
OP needs to wait for the A/D like that:
Rich (BB code):
while(!ADIF);
4. Use MPLAB X + templates. This would save OP from such a bad starter for a program.