PIC 16F877 assembly code read analog signal

Discussion in 'Programmer's Corner' started by chilly, Sep 19, 2008.

Thread Status:
Not open for further replies.
  1. chilly

    Thread Starter New Member

    Sep 16, 2008
    7
    0
    Could anyone suggest me how to do this program?
    This program will read analog input from potentiometer then show the value in PortC. When all bit of PORTC is set then the program will write 1 in RE2. If RC7=1 then the program will write 1 in RE1, If RC7=0 then the program will write 1 in RE0 and clear RE1
    Here is my source code
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I have organized the code using the CODE tags.

    hgmjr

    Code ( (Unknown Language)):
    1.  
    2. LIST P=16F877,W=-302
    3. INCLUDE P16F877.INC
    4. __CONFIG 0x3D32 ; XTAL 20 MHZ. HS GAIN
    5.  
    6. include "p16f877.inc"
    7.  
    8. ADCon0 EQU H'001F'
    9. ADCon1 EQU H'009F'
    10.  
    11. ; Start at the reset vector
    12. org 0x000
    13. goto Start
    14. org 0x004
    15. Interrupt
    16.          retfie
    17. Start
    18.          MOVLW    B'00000000'  ; PORTE = output
    19.          MOVWF    TRISE
    20.          bsf      STATUS,RP0   ;bank 1
    21.          bcf      STATUS,RP1
    22.          movlw    H'00'
    23.          movwf    TRISC        ;portc [7-0] outputs
    24.          clrf     ADCon1       ;left justified, all inputs a/d
    25.          bcf      STATUS,RP0   ;bank 0
    26.          movlw    B'01000001'  ;Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
    27.          movwf    ADCon0
    28.  
    29. Main
    30.          call     ad_portc
    31.          call     Loop1
    32.          call     Loop2
    33.          goto     Main
    34.  
    35.  
    36.  
    37. ;wait for acquision time (20uS)
    38. ;(non-critical for this test)
    39.  
    40. ad_portc
    41.          bsf      ADCon0,GO    ;Start A/D conversion
    42. Wait
    43.          btfsc    ADCon0,GO    ;Wait for conversion to complete
    44.          goto     Wait
    45.  
    46.          movf     ADRESH,W     ;write A/D result to PORTC
    47.          movwf    PORTC        ;LEDs
    48.          return
    49.  
    50. Loop1
    51.          movlw    0x31
    52.          xorwf    PORTC,w
    53.          btfsc    STATUS,Z
    54.          bsf      PORTE,3
    55.          bcf      PORTE,3
    56.          goto     Loop1
    57.  
    58. Loop2
    59.          btfss    PORTC,7
    60.          bsf      PORTE,1
    61.          bsf      PORTE,2
    62.          btfss    PORTC,7
    63.          bcf      PORTE,2
    64.          bcf      PORTE,1
    65.          goto     Loop2
    66.  
    67. end
    68.  
     
Loading...
Thread Status:
Not open for further replies.