Problem setting PIC16F877A as Analogue Input

Thread Starter

lloydi12345

Joined Aug 15, 2010
103
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:

Rich (BB code):
    list        p=16f877A    ; list directive to define processor
    #include    <p16f877A.inc>    ; processor specific variable definitions
    
    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF




CBLOCK 0x0c    
    FIRST
    SECOND
    THIRD
ENDC


      ORG     0x000            
      goto    main              ; go to beginning of program

     ORG     0x004 
; isr code can go here 


main  

BANKSEL TRISA 
MOVLW 0XFF
MOVWF TRISA
BANKSEL TRISB
MOVLW 0X00
MOVWF TRISB
BANKSEL PORTB 

FORWARD:     

             MOVLW 0X01
            MOVWF PORTB
            call delay
            BTFSS PORTA,0
            GOTO LEFT_EDGE             ;0XXX
            GOTO LEFT_NO_EDGE        ;1XXX

LEFT_EDGE: ;0XXX 

             BTFSS PORTA,1
            GOTO BACKWARD    ;00XX
            GOTO TURN_RIGHT    ;01XX

LEFT_NO_EDGE:    ;1XXX 

             BTFSS PORTA,1
            GOTO TURN_LEFT    ;10XX
            GOTO CHECK_OBSTACLES    ;11XX

CHECK_OBSTACLES:    ;11XX 

             BTFSS PORTA,2
            GOTO LEFT_SENSOR_OFF    ;110X
            GOTO LEFT_SENSOR_ON        ;111X

LEFT_SENSOR_OFF: 

             BTFSS PORTA,3
            GOTO FORWARD        ;1100
            GOTO TURN_LEFT        ;1101

LEFT_SENSOR_ON: 

             BTFSS PORTA,3        
            GOTO TURN_RIGHT        ;1110
            GOTO BACKWARD        ;1111

TURN_LEFT: 

             MOVLW B'00000101'
            MOVWF PORTB
            call delay
            call delay
            call delay
            call delay
            call delay
            GOTO FORWARD

TURN_RIGHT: 

             MOVLW B'00001001'
            MOVWF PORTB
            call delay
            call delay
            call delay
            call delay
            call delay
            GOTO FORWARD

BACKWARD: 

             MOVLW B'00000110'
            MOVWF PORTB
            call delay
            call delay
            call delay
            call delay
            call delay
            GOTO TURN_RIGHT

delay                        ;    1 second delay 
        MOVLW .150
        MOVWF THIRD
LOOP_1_SEC:
        MOVLW .255
        MOVWF SECOND
LOOP_125_MS:
        MOVLW .255
        MOVWF FIRST
LOOP_.5_MS:
        NOP
        DECFSZ    FIRST, F
        GOTO    LOOP_.5_MS
        
        DECFSZ     SECOND, F
        GOTO    LOOP_125_MS
        
        DECFSZ    THIRD, F
        GOTO    LOOP_1_SEC
        return









             END                       ; directive 'end of program'
I hope you can help me
 
Last edited:
Top