PIC16F877A ADC Problem

Thread Starter

amitha

Joined Sep 14, 2010
1
hi, i am trying to read an adc input and output the result at PORTC using assembly language, but the simulation in proteus give me no output, please help me find where is my mistake, tq

Rich (BB code):
INCLUDE "P16F877A.INC"
ERRORLEVEL    0,    -302        ;suppress bank selection messages

ADCON1 EQU 9FH
ADCON0 EQU 1FH
go EQU 2
ADRESL EQU 9EH
PORTC EQU 07H 
TRISC EQU 87H
PORTA EQU 05H
TRISA EQU 85H


ORG 0x000
goto main

main



banksel ADCON1
movlw b'10000000' ; configure all channel as analog n vref = vdd n gnd
movwf ADCON1
banksel ADCON0
movlw b'10000001' ; ch0 as anolog input n fosc/32
movwf ADCON0
banksel TRISC
movlw b'00000000'
movwf TRISC
banksel PORTC
clrf  PORTC
banksel PORTA
clrf PORTA

loop

        banksel ADCON0
        bsf ADCON0,go
        
        back
        CALL delay
        banksel ADCON0
        btfsc ADCON0,go
        goto back
        
        BANKSEL ADRESL
        movf    ADRESL,W
        BANKSEL PORTC
        movwf     PORTC
        goto loop


delay
        movlw d'6'
        movwf 20h
looping nop
        nop
        decfsz 20h
        goto looping
        return

end
 
Never used proteus and I don't know C but I wonder if it shows not output because the simulator is showing x00h on the ADC and as such shows x00h on portC
 
I don't see where you set-up TRISA... what pin is the input?

Also, in the real world, you would want some type of delay after sending it to PORTC. You have it in a continuous loop that will keep overwriting what is in PORTC.
 

Markd77

Joined Sep 7, 2009
2,806
TRISA defaults to inputs so shouldn't be a problem.
There is no need to define TRISC, PORTC, etc - they are all in the include file.
What is the device CONFIG? That could be causing problems.
 
Top