Help with GOSUB


Closed Thread
Results 1 to 17 of 17

Thread: Help with GOSUB

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Help with GOSUB

    Hi Jim,
    It was the only example I could find where I could pulse a pin for a certain number of times.
    That's not what that particullar code example does. It IS "indexing" port pins starting at PortB.0 and ending at PortB.7 setting them low, one by one.

    I'm not trying to do any "array indexing".
    I figured you're not trying to but that IS effectively what you're doing ;-)

    PortA.3 = 1 will set PortA.3 high - this is what you want.
    PortA.3[3]=1 will set PortA.6 high because you're adding an offset of 3 - not what you want in this case.
    PortA.3[i] will set "something" high - what that "something" is depends on the value of i which is incrementing each time thru the loop - definitely not what you want in this case.

    All I'm doing is pulsing the RD pin low 65535 times. Each time the pin is pulsed low the i variable counts up and when the count reaches 65535, it stops pulsing and continues on with what was next in the code.
    Yes and no. You're actually pulsing the pin 65536 times, since you're starting at 0 and stopping at 65535 but I Think 65536 is what you want. And since the i variable is couting up you're setting 65536 consecuitive bits, starting at PortA.3 high.

    As a test, try
    Code:
    dat:
    RD = 1
    For i = 0 to 65535
       RD = 0      ' Pull pin low
       PAUSEUS 10    ' Wait 10us
       RD = 1    ' Pull pin high
       PAUSEUS 10    ' Wait 10us
    NEXT
    RETURN
    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Help with GOSUB

    Oh, one more thing....which I should have caught from the start:
    Before the dat subroutine you need to put a GOTO Mainloop, otherwise the execution will "fall into" the dat subroutine after the last GOSUB dat you have in there. When it then hits the RETURN there's no matching GOSUB and you'll have a stack underflow and it goes off to la-la-land. I suspect THAT is what you're seeing but the issues with unintentional "array indexing" is still very much relevant!

    /Henrik.

Similar Threads

  1. gosub - return
    By l_gaminde in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th August 2010, 11:21
  2. On...gosub
    By circuitpro in forum PBP Wish List
    Replies: 5
    Last Post: - 7th December 2009, 22:40
  3. If ... Then Gosub <> If ... Then Goto?
    By oldtoddler in forum General
    Replies: 6
    Last Post: - 27th February 2006, 12:52
  4. gosub and if-then working together?
    By bartman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd November 2005, 14:54
  5. GoSub Problem
    By ghoot in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th May 2004, 16:15

Members who have read this thread : 0

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