bogusmeister
Junior Member level 2
Hi guys!. i've been using this ADC of pic16f877a with the code that i got. it uses channel0 sample and 1 analog input for the conversion.
now my problem is when i want to use 2channels for 2 analog inputs i cant get it working. the LED's just blinking.. what i did is that i repeat this code and change the value of adcon0 for channel1 and adcon1 for 2 analog inputs.
could you please help me how to program the ADC if im gonna use more than one channel for analog inputs? thank you very much
Code:
LIST p=16f877a
; Include file, change directory if needed
INCLUDE "p16f877A.inc"
__CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF
ERRORLEVEL -302
; Start at the reset vector
ORG 0x000
NOP
Start
BANKSEL PORTD
CLRF PORTD ;Clear PORTD
MOVLW B'01000001' ;Fosc/8, A/D enabled, Sample Channel 0
MOVWF ADCON0
BANKSEL OPTION_REG
MOVLW B'10000111' ;TMR0 prescaler, 1:256
MOVWF OPTION_REG
CLRF TRISD ;PORTD all outputs
MOVLW B'00001110' ;Left justify, 1 analog channel
MOVWF ADCON1 ;VDD and VSS references
BANKSEL PORTD
Main
BCF INTCON,T0IF
Loop
BTFSS INTCON,T0IF ;Wait for Timer0 to timeout
GOTO Loop
BSF ADCON0,GO ;Start A/D conversion for channel 0
Wait
BTFSS PIR1,ADIF ;Wait for conversion to complete
GOTO Wait
MOVF ADRESH,W ;Write A/D result to PORTD
MOVWF PORTD ;LEDs
BCF PIR1,ADIF ;Clear the completion flag
GOTO Loop ;Do it again
END
now my problem is when i want to use 2channels for 2 analog inputs i cant get it working. the LED's just blinking.. what i did is that i repeat this code and change the value of adcon0 for channel1 and adcon1 for 2 analog inputs.
could you please help me how to program the ADC if im gonna use more than one channel for analog inputs? thank you very much