PIC16F877A ADC Problem

Discussion in 'Embedded Systems and Microcontrollers' started by amitha, Sep 14, 2010.

  1. amitha

    Thread Starter New Member

    Sep 14, 2010
    1
    0
    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

    Code ( (Unknown Language)):
    1. INCLUDE "P16F877A.INC"
    2. ERRORLEVEL    0,    -302        ;suppress bank selection messages
    3.  
    4. ADCON1 EQU 9FH
    5. ADCON0 EQU 1FH
    6. go EQU 2
    7. ADRESL EQU 9EH
    8. PORTC EQU 07H
    9. TRISC EQU 87H
    10. PORTA EQU 05H
    11. TRISA EQU 85H
    12.  
    13.  
    14. ORG 0x000
    15. goto main
    16.  
    17. main
    18.  
    19.  
    20.  
    21. banksel ADCON1
    22. movlw b'10000000' ; configure all channel as analog n vref = vdd n gnd
    23. movwf ADCON1
    24. banksel ADCON0
    25. movlw b'10000001' ; ch0 as anolog input n fosc/32
    26. movwf ADCON0
    27. banksel TRISC
    28. movlw b'00000000'
    29. movwf TRISC
    30. banksel PORTC
    31. clrf  PORTC
    32. banksel PORTA
    33. clrf PORTA
    34.  
    35. loop
    36.  
    37.         banksel ADCON0
    38.         bsf ADCON0,go
    39.        
    40.         back
    41.         CALL delay
    42.         banksel ADCON0
    43.         btfsc ADCON0,go
    44.         goto back
    45.        
    46.         BANKSEL ADRESL
    47.         movf    ADRESL,W
    48.         BANKSEL PORTC
    49.         movwf     PORTC
    50.         goto loop
    51.  
    52.  
    53. delay
    54.         movlw d'6'
    55.         movwf 20h
    56. looping nop
    57.         nop
    58.         decfsz 20h
    59.         goto looping
    60.         return
    61.  
    62. end
    63.  
     
  2. wannaBinventor

    Member

    Apr 8, 2010
    179
    4
    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
     
  3. elementalrage

    Active Member

    Jul 30, 2009
    59
    3
    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.
     
  4. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
Loading...