Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem using Port A on PIC16F877A

Status
Not open for further replies.

lloydi12345

Member level 4
Joined
Aug 31, 2010
Messages
77
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,953
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:
    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 :sad:
 

you should read the datasheet, particularly the section on IO ports. it has the answer for you right there.
 

PORT A is the delicatest port of the controller than any other port. So proper allocation of input/output pins & analog/digital pins will lead to mismatch in the value outputted. So do check your allocation with the datasheet of the controller & do cross check that.
Regards,
Jerin. :)
 

before you do anything you need to set it to the right configuration :) such as analog input or digital input
 

I got it now sir.. i should configure first the inputs at TRISA since pin A has so many uses
 

usually PORT A is dedicated to analog signal i.e ADC. IF u wannt accesess PORT A plse define TRISA(try state condition) propery and define the port pinc as ur cosideration like #define PORTA portabits.bit(0-7) ,SET TRISA
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top