Hi. I am trying to operate the A-to-D module in the 16F877A for the first time. For some reason, I am not getting a result. Here is my code. As you can see, I am trying to get the resulting 10-bit digtial number and light 10 LEDs (RB0-RB7 and RD0-RD1). Please help. (the analog input to channel 0 is the output of a potentiometer powerd from Vdd)
LIST P=16F877A
#INCLUDE "P16F877A.INC"
ORG 0x0000
bcf STATUS, RP1
bsf STATUS, RP0
movlw b'00000000'
movwf TRISB
movlw b'00000000'
movwf TRISD
movlw b'00000001'
movwf TRISA
bcf TRISE,4
bcf ADCON1,0
bsf ADCON1,1
bsf ADCON1,2
bsf ADCON1,3
bcf ADCON1,6
bsf ADCON1,7
bcf STATUS, RP1
bcf STATUS, RP0
bcf ADCON0,3
bcf ADCON0,4
bcf ADCON0,5
bcf ADCON0,6
bsf ADCON0,7
bsf ADCON0,0
call delay
clrf PORTB
main
bsf ADCON0,GO ; start conversion
check
btfsc ADCON0,GO
goto check
bsf STATUS, RP0
movlw ADRESL
movwf PORTB
bcf STATUS, RP0
movlw ADRESH
movwf PORTD
goto main
end
LIST P=16F877A
#INCLUDE "P16F877A.INC"
ORG 0x0000
bcf STATUS, RP1
bsf STATUS, RP0
movlw b'00000000'
movwf TRISB
movlw b'00000000'
movwf TRISD
movlw b'00000001'
movwf TRISA
bcf TRISE,4
bcf ADCON1,0
bsf ADCON1,1
bsf ADCON1,2
bsf ADCON1,3
bcf ADCON1,6
bsf ADCON1,7
bcf STATUS, RP1
bcf STATUS, RP0
bcf ADCON0,3
bcf ADCON0,4
bcf ADCON0,5
bcf ADCON0,6
bsf ADCON0,7
bsf ADCON0,0
call delay
clrf PORTB
main
bsf ADCON0,GO ; start conversion
check
btfsc ADCON0,GO
goto check
bsf STATUS, RP0
movlw ADRESL
movwf PORTB
bcf STATUS, RP0
movlw ADRESH
movwf PORTD
goto main
end