Shop OBEX P1 Docs P2 Docs Learn Events
Another Pair of eyes on SubRoutine Parameter Poblem — Parallax Forums

Another Pair of eyes on SubRoutine Parameter Poblem

John KauffmanJohn Kauffman Posts: 653
edited 2008-03-22 13:49 in General Discussion
Can anyone spot the problem with code below that communicates with a serial device?
I get an assembly error on both GoSub lines:· "Invalid Number Of Paramaters."

Thanks.

'
' Device Settings
'
' external resonator Murata "400C.625"
DEVICE· SX28, OSCHS2, TURBO, STACKX, OPTIONX
FREQ··· 28_000_000

'
IO Pins
Spin·pin·RA.0·' Serial Pin

'================================================
· PROGRAM Start
'================================================

'
Subroutines / Jump Table
TX_BYTE sub 1

'
Program Code
Main:
·LOW SPin········· ' Start with serial pin low
·PAUSE 1000······· ' Allow device to stabilize
·GoSub TX_Byte 5
·GoSub Tx_byte "a"
·GoTo Main

TX_Byte:
· SEROUT Spin, N2400 __PARAM1
·endsub

Comments

  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2008-03-22 13:16
    Hello John,

    I found a few things and I think the code below will do what you want. (don't worry, these are easy things to overlook and everyone does it at least once!)

    The part that was causing the error is that when you use GOSUB it doesn't expect to pass any variables. You just need to use the subroutine name alone. I also added the sub and removed the : in the definition of the subroutine to remain consistent. The definition and calling method you had was mixed between the two formats. Since it has changed as SX/B has matured I can see how someone could easily do that.

    Another thing that I noticed was that a comma was missing the in SEROUT command.

    The last thing it needed was with the PROGRAM Start. Start is a label that doesn't exist in the program. It could have been changed to Main but I just added a Start label since you may way to setup some things before getting to your main code. To help clean up the code I made all the occurrences of TX_BYTE the same case.

    Compiles fine now.


    '
    ' Device Settings
    '
    ' external resonator Murata "400C.625"
    DEVICE SX28, OSCHS2, TURBO, STACKX, OPTIONX
    FREQ 28_000_000

    '
    IO Pins
    Spin pin RA.0 ' Serial Pin

    '
    Subroutines / Jump Table
    TX_BYTE sub 1

    '================================================
    PROGRAM Start
    '================================================

    Start:

    ' Setup variable, etc

    '
    Program Code
    Main:
    LOW SPin ' Start with serial pin low
    PAUSE 1000 ' Allow device to stabilize
    TX_BYTE 5
    TX_BYTE "*"
    GoTo Main

    sub TX_BYTE
    SEROUT Spin, N2400, __PARAM1
    endsub

    Post Edited (RobotWorkshop) : 3/22/2008 6:07:53 PM GMT
  • John KauffmanJohn Kauffman Posts: 653
    edited 2008-03-22 13:49
    Brilliant - understanding that there is a "new" and "old" system solves a number of problems in several of my projects.

    Thanks for your time to provide such a thorough explanation.
Sign In or Register to comment.