12F510 CALL subroutine problem ...


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2010
    Posts
    30

    Default 12F510 CALL subroutine problem ...

    Hello to all,
    i am having a headache using CALL in 12F510...see that...

    The PIC gets a continuous CLK in pins GPIO.3 and .4
    (This is only a testing part of the full program , in order to understand what caused the full program to WDT endlessly)


    So...THIS TEST CODE IS NOT WORKING...it watchdogs endlessly....

    CODE/
    -------------------------------------------------------------------------------

    @ DEVICE pic12F510, INTRC_OSC
    @ DEVICE pic12F510, WDT_ON
    @ DEVICE pic12F510, MCLR_OFF
    @ DEVICE pic12F510, PROTECT_OFF

    DEFINE OSC 4

    IN_A VAR GPIO.4
    IN_B VAR GPIO.3
    OUT_A VAR GPIO.5
    OUT_B VAR GPIO.1
    LED VAR GPIO.5

    ADCON0.6 = 0 ' A/D OFF
    ADCON0.7 = 0 'A/D OFF
    CM1CON0.3 = 0 'COMPARATOR OFF
    OPTION_REG.5 = 0 ' TOCKI OFF

    TRISIO = 00011100

    MAIN_LOOP:
    CLEARWDT

    CALL WAIT_HI_IN_A

    OUT_A = 1
    OUT_B = 1

    pauseus 100
    OUT_A = 0
    OUT_B = 0

    GOTO MAIN_LOOP


    WAIT_HI_IN_A:
    CLEARWDT
    IF IN_A = 0 THEN GOTO WAIT_HI_IN_A
    return


    -----------------------------------------------------------------------
    /CODE


    But... if i move the WAIT_HI_IN_A routine inside the mainloop ... it works! .... no WDT timeout , and pulses going out of the GPIO outputs .... what is happening?

    -----------------------------------------------------------------------
    CODE/

    @ DEVICE pic12F510, INTRC_OSC
    @ DEVICE pic12F510, WDT_ON
    @ DEVICE pic12F510, MCLR_OFF
    @ DEVICE pic12F510, PROTECT_OFF

    DEFINE OSC 4

    IN_A VAR GPIO.4
    IN_B VAR GPIO.3
    OUT_A VAR GPIO.5
    OUT_B VAR GPIO.1
    LED VAR GPIO.5

    ADCON0.6 = 0 ' A/D OFF
    ADCON0.7 = 0 'A/D OFF
    CM1CON0.3 = 0 'COMPARATOR OFF
    OPTION_REG.5 = 0 ' TOCKI OFF

    TRISIO = 00011100

    MAIN_LOOP:
    CLEARWDT

    WAIT_HI_IN_A:
    CLEARWDT
    IF IN_A = 0 THEN GOTO WAIT_HI_IN_A


    OUT_A = 1
    OUT_B = 1

    pauseus 100
    OUT_A = 0
    OUT_B = 0

    GOTO MAIN_LOOP

    -------------------------------------------------------------------------------------------------
    /CODE




    I also have a second problem with the above code...
    The original plan was ... "OUT_A VAR GPIO.0" , but GPIO.0 does really strange things...
    i get unstable triangle voltages , so for now i use GPIO.5 instead which works fine (but pcb's have already manufactured , due to hurry )...
    Last edited by LakisFM1; - 15th November 2011 at 00:13.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: 12F510 CALL subroutine problem ...

    Hi,
    CALL is used to execute an assembly subroutine (preceeded with an underscore) but it looks to me like your subroutine is written in PBP.
    Try using GOSUB instead of CALL.

    /Henrik.

  3. #3
    Join Date
    Feb 2010
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: 12F510 CALL subroutine problem ...

    T H A N K S !!!! ..... THAT WAS IT!

    (and solved all the problems ... including the strange behaviour of GPIO.0....)

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts