pic16f876 ADC

Status
Not open for further replies.
i try to convert analog to digital using pic16f876 and input signal= 3v
Vref+=5v,Vref=0....so that we sould get 3*1024/5=614 decimal= 266 hex
when we make ADFM=1 and we use this code:
movfw ADRESL
movwf PORTC

movfw ADRESH
movwf PORTB


we get the result only the ADRESH=2 on portB and portC
but we do not get ADRESL whis equal to 66 on portC
why... could any on tell me how we make ADRESH on portB and the same tme
ADRESL=portC to get 2 on portB and 66 on portC

and this is the complete code :



list p=16f876
#include <P16f876.INC>

ERRORLEVEL -302


wait EQU 0x20

init

bsf STATUS, RP0 ; auf Bank 1 umschalten
movlw B'00000000' ; PortB alle output
movwf TRISB
movwf TRISC
bcf STATUS, RP0 ; auf Bank 0 zurückschalten
clrf PORTB ; alle LEDs ausschalten
clrf PORTC

BSF ADCON0, 0 ; ADON=1


BCF ADCON0, 5 ; ADCHS2=0
BCF ADCON0, 4 ; ADCHS1=0
BCF ADCON0, 3 ; ADCHS0=0


BSF ADCON0, 7 ; ADCS1=1
BSF ADCON0, 6 ; ADCS0=1


BSF STATUS,RP0 ; Bank1
BSF ADCON1, 7 ; ADFM=1
BCF STATUS,RP0 ; Bank0




Main

BSF ADCON0, 2 ; ADC starten
loop
BTFSC ADCON0, 2 ; ist der ADC fertig?
GOTO loop ; nein, weiter warten



movfw ADRESL ; obere 8 Bit auslesen
movwf PORTC


movfw ADRESH ; obere 8 Bit auslesen
movwf PORTB ; obere 8 Bit nach PortB



clrf wait
warten
DECFSZ wait, f
goto warten

goto Main

end
 
ADRESL and ADRESH are in different banks, you need to switch banks - check my analogue tutorial for full details of using the analogue inputs.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…