Problem setting PIC16F877A as Analogue Input

Discussion in 'Embedded Systems and Microcontrollers' started by lloydi12345, Oct 4, 2010.

  1. lloydi12345

    Thread Starter Member

    Aug 15, 2010
    103
    0
    Good day, I'm not sure if the title is right.. I would like to ask for help because my PIC16F877A doesn't recognize the input voltage which is 3.9v and 0v from the comparator LM324's output voltage. I am using Port A as an input and test it if it's logic 1 or logic 0 then the motors will move. I used this code for my Edge Detector Mobot (based on the concept of line following mobot), here it is:

    Code ( (Unknown Language)):
    1.  
    2.     list        p=16f877A    ; list directive to define processor
    3.     #include    <p16f877A.inc>    ; processor specific variable definitions
    4.    
    5.     __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
    6.  
    7.  
    8.  
    9.  
    10. CBLOCK 0x0c    
    11.     FIRST
    12.     SECOND
    13.     THIRD
    14. ENDC
    15.  
    16.  
    17.       ORG     0x000            
    18.       goto    main              ; go to beginning of program
    19.  
    20.      ORG     0x004
    21. ; isr code can go here
    22.  
    23.  
    24. main  
    25.  
    26. BANKSEL TRISA
    27. MOVLW 0XFF
    28. MOVWF TRISA
    29. BANKSEL TRISB
    30. MOVLW 0X00
    31. MOVWF TRISB
    32. BANKSEL PORTB
    33.  
    34. FORWARD:    
    35.  
    36.              MOVLW 0X01
    37.             MOVWF PORTB
    38.             call delay
    39.             BTFSS PORTA,0
    40.             GOTO LEFT_EDGE             ;0XXX
    41.             GOTO LEFT_NO_EDGE        ;1XXX
    42.  
    43. LEFT_EDGE: ;0XXX
    44.  
    45.              BTFSS PORTA,1
    46.             GOTO BACKWARD    ;00XX
    47.             GOTO TURN_RIGHT    ;01XX
    48.  
    49. LEFT_NO_EDGE:    ;1XXX
    50.  
    51.              BTFSS PORTA,1
    52.             GOTO TURN_LEFT    ;10XX
    53.             GOTO CHECK_OBSTACLES    ;11XX
    54.  
    55. CHECK_OBSTACLES:    ;11XX
    56.  
    57.              BTFSS PORTA,2
    58.             GOTO LEFT_SENSOR_OFF    ;110X
    59.             GOTO LEFT_SENSOR_ON        ;111X
    60.  
    61. LEFT_SENSOR_OFF:
    62.  
    63.              BTFSS PORTA,3
    64.             GOTO FORWARD        ;1100
    65.             GOTO TURN_LEFT        ;1101
    66.  
    67. LEFT_SENSOR_ON:
    68.  
    69.              BTFSS PORTA,3        
    70.             GOTO TURN_RIGHT        ;1110
    71.             GOTO BACKWARD        ;1111
    72.  
    73. TURN_LEFT:
    74.  
    75.              MOVLW B'00000101'
    76.             MOVWF PORTB
    77.             call delay
    78.             call delay
    79.             call delay
    80.             call delay
    81.             call delay
    82.             GOTO FORWARD
    83.  
    84. TURN_RIGHT:
    85.  
    86.              MOVLW B'00001001'
    87.             MOVWF PORTB
    88.             call delay
    89.             call delay
    90.             call delay
    91.             call delay
    92.             call delay
    93.             GOTO FORWARD
    94.  
    95. BACKWARD:
    96.  
    97.              MOVLW B'00000110'
    98.             MOVWF PORTB
    99.             call delay
    100.             call delay
    101.             call delay
    102.             call delay
    103.             call delay
    104.             GOTO TURN_RIGHT
    105.  
    106. delay                        ;    1 second delay
    107.         MOVLW .150
    108.         MOVWF THIRD
    109. LOOP_1_SEC:
    110.         MOVLW .255
    111.         MOVWF SECOND
    112. LOOP_125_MS:
    113.         MOVLW .255
    114.         MOVWF FIRST
    115. LOOP_.5_MS:
    116.         NOP
    117.         DECFSZ    FIRST, F
    118.         GOTO    LOOP_.5_MS
    119.        
    120.         DECFSZ     SECOND, F
    121.         GOTO    LOOP_125_MS
    122.        
    123.         DECFSZ    THIRD, F
    124.         GOTO    LOOP_1_SEC
    125.         return
    126.  
    127.  
    128.  
    129.  
    130.  
    131.  
    132.  
    133.  
    134.  
    135.              END                       ; directive 'end of program'
    136.  
    I hope you can help me
     
    Last edited: Oct 4, 2010
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I'm not sure if this is the problem but you need to change the cblock to:
    CBLOCK 0x20
     
Loading...