[PIC16F84A]Need Help About Program

Discussion in 'Embedded Systems and Microcontrollers' started by jezznar, Feb 4, 2009.

  1. jezznar

    Thread Starter New Member

    Feb 4, 2009
    4
    0
    I've been trying to figure out what in the world is wrong with my program :(
    Im using a PDIP/SOIC package...
    Please help me try to analyze it... well first of all, the program is intended to control a motor.
    2 sensors(LDR) are attached to RB4(pin10) and RB5(pin11) for sensor1 and sensor2, respectively..
    The program intends to check if someone passes through sensor1, if someone does, it will signal the motor to activate on a clockwise basis. afterwhich, if sensor2 detects that someone passes thru, the motor will activate and will revolve on a counterclockwise basis.
    this is actually a drawbridge.. please help me..
    FYI. The upcount and downcount refers to a counter that tells the user how many passed through sensor1 and will decrement every after someone passes through sensor 2. This isn't really the big prob..the big prob is why it isnt signalling the motor to start :confused:

    I have tried checking out some newbie guides but still its not working.. please help me.

    [​IMG]

    [​IMG]

    ;REVISED PRIOR TO SUGGESTIONS
    i found out a redundancy of my declared characters and a few inconsistencies. my bad, i think i was really having a huge headache last night trying to figure it out.. would you please try to check if it will be good now?





    ;THE PROGRAM.
    processor 16f84
    include <p16f84.inc>
    OPTION_REG.7=0 (set weak pullup on portB)
    __config _XT_OSC&_WDT_OFF&_PWRTE_ON
    ;-------------------------------------------------------------------------;
    ; Here we define our own personal registers and give them names ;
    ;-------------------------------------------------------------------------;
    cblock 0ch
    j
    ones
    ;z
    endc
    errorlevel-302
    ;-------------------------------------------------------------------------;
    ; Here we give names to some numbers to make their use more clear ;
    ;-------------------------------------------------------------------------;
    #define _in PORTB,4
    #define _out PORTB,5
    #define for PORTB,6
    #define rev PORTB,7
    #define _1 PORTA,2


    ;-------------------------------------------------------------------------;
    ; We set the start of code to originate at location zero ;
    ;-------------------------------------------------------------------------;

    org 0
    ;-------------------------------------------------------------------------;
    ; Initialization routine sets up ports and timer ;
    ;-------------------------------------------------------------------------;
    clrf ones

    bsf STATUS,RP0
    movlw b'11000' ;
    movwf TRISA
    movlw b'00110000' ;
    movwf TRISB
    bcf STATUS,RP0

    call delay


    ;-------------------------------------------------------------------------;
    ; Main routine ;
    ;-------------------------------------------------------------------------;

    main:
    call check1
    btfsc _in
    goto upcount
    btfsc _out
    goto downcount
    goto main

    check1:
    movf ones,w
    sublw .0
    btfss STATUS,Z
    goto up_tulay
    goto down_tulay

    check:
    btfsc _out
    goto check
    btfsc _in
    goto check
    goto main

    ;bridge up
    up_tulay:
    bsf for
    bcf rev
    return
    ;bridge down
    down_tulay:
    bcf for
    bsf rev
    return

    ;-------------------------------------------------------------------------;
    ; Increments the display up to D'9' ; ;
    ;-------------------------------------------------------------------------;
    upcount:

    incf ones,F
    movf ones,w
    sublw h'0A'
    btfss STATUS,Z
    goto check
    clrf ones
    goto down_only
    ;-------------------------------------------------------------------------;
    ; Decrements the display up to D'0' ; ;
    ;-------------------------------------------------------------------------;

    downcount:

    decf ones,F
    movf ones,w
    sublw .255
    btfss STATUS,Z
    goto check
    goto up_only
    ;-------------------------------------------------------------------------;
    ; ; ;
    ;-------------------------------------------------------------------------;

    up_only:
    movlw .0
    movwf ones
    call check1

    btfsc _in
    goto check_up1
    btfsc _out
    goto up_only

    check_up1:

    btfsc _in
    goto upcount
    goto check_up1

    down_only:
    movlw .9
    movwf ones
    call check1


    btfsc _out
    goto check_down1
    btfsc _in
    goto down_only

    check_down1:

    btfsc _out
    goto downcount
    goto check_down1

    return

    delay:
    movlw h'ff'
    movwf j
    decfsz j,f
    goto $-1
    return


    end

    movf ones,w
    sublw .0
    btfss STATUS,z
    goto up_tulay
    goto down_tulay
     
    Last edited: Feb 4, 2009
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    In the schematic, you are using RB4 and RB5 for inputs and RB6 and RB7 for outputs. But in the code you are configuring RA0 to RA2 as outputs, RA3 and RA4 as inputs and all PORTB as outputs. In the definition, you are using RA3 and RA4 as inputs and RB0 and RB1 as outputs. What's going on here?
     
  3. jezznar

    Thread Starter New Member

    Feb 4, 2009
    4
    0
    I have added a flowchart so that you guys can take a look see of what im thinking about...

    @n9352527

    ermmmm yeah i think i was getting beaten up by drowsiness...
    here's the a revision. pls do check :)


    #define _in PORTB,4
    #define _out PORTB,5
    #define for PORTB,6
    #define rev PORTB,7

    org 0

    clrf ones

    bsf STATUS,RP0
    movlw b'11111';
    movwf TRISA
    movlw b'00110000';
    movwf TRISB
    bcf STATUS,RP0



    @Alberto
    how do i disable unused pins for PORTA? i really dont have any use for the ports on it.

    @both
    Thank you :)
     
    Last edited: Feb 4, 2009
  4. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    Seems ok to me. Have you try it?
     
  5. jezznar

    Thread Starter New Member

    Feb 4, 2009
    4
    0
    I have yet to burn the program to my IC. I'm at school at the moment taking a look at a few handbooks for IC programming. I really would want to admit that I'm a newbie in terms of IC programming. :)
     
  6. jezznar

    Thread Starter New Member

    Feb 4, 2009
    4
    0
    sorry i wasn't able to reply last night. I lost my internet :mad: anyway.
    I think I have to go over everything, It won't work :( sigh.
     
Loading...