Shop OBEX P1 Docs P2 Docs Learn Events
Need help creating a sub and transferring parameters — Parallax Forums

Need help creating a sub and transferring parameters

eagletalontimeagletalontim Posts: 1,399
edited 2009-01-11 15:21 in General Discussion
I finally got my serial LCD in and I am messing around with some of my own functions to use it. Right now, I am attempting to create a sub that I can pass 3 parameters to it. The first parameter will be a string or just one character. The second parameter will be a number 0 or 1 and the third parameter will be a number 1 through 16. I have no idea what to set the SUB to : my_sub SUB 3? Would each parameter be _WPARAM12 and/or _PARAM#?

Comments

  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-01-08 03:25
    ok, nevermind. I got it [noparse]:)[/noparse]
  • BeanBean Posts: 8,129
    edited 2009-01-08 14:05
    Well for anyone else that wonders how to do it...

    If the first parameter is a character, then __PARAMCNT will be 3, the character will be in __PARAM1, the 0 or 1 will be in __PARAM2 and the 1-16 will be in __PARAM3.

    If the first parameter is a string, then __PARAMCNT will be 4, the string address will be in __WPARAM12, the 0 or 1 will be in __PARAM3, and the 1-16 will be in __PARAM4.

    You would define the subroutine as

    LCDOut SUB 3,4

    SUB LCDOut
    · IF __PARAMCNT = 3 THEN
    ··· ' Handle character sent
    · ELSE
    ··· ' Handle string sent
    · ENDIF
    ENDSUB

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ·The next time you need a hero don't look up in the sky...Look in the mirror.


    ·
  • Shawn LoweShawn Lowe Posts: 635
    edited 2009-01-08 14:19
    Thanks for explaining further Bean!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-01-11 15:00
    I ran into another problem and it is confusing me yet again....

    I have 2 chips that are synced together. One sends data, the other receives. I have a sub called SEND_BYTE that should be used as SEND_BYTE byte1, byte2, byte3. When I use the sub, only byte3 is sent. The other 2 are not sent for some reason. If I simply put the SEROUT commands in the Main, they all send perfectly. I need help figuring what to set the SUB as and if the PARAM values are correct.

    Here is my code :
    SEND_BYTE    SUB    3
    
    Start:
      PLP_A = %0001                    ' pull up unused pins
      PLP_B = %00000000
      PLP_C = %00000000
      temp3 = 255
      temp1 = 13
      temp2 = 27
    Main:
      DEC temp3
      SEND_BYTE temp1, temp2, temp3
      wait 2000
      GOTO Main
    
    ........
    
    SEND_BYTE:
      SEROUT RX, Baud, SYNC
      SEROUT RX, Baud, __PARAM1
      SEROUT RX, Baud, __PARAM2
      SEROUT RX, Baud, __PARAM3
      RETURN
    



    Thanks for the help in advance!

    Post Edited (eagletalontim) : 1/11/2009 3:08:50 PM GMT
  • ZootZoot Posts: 2,227
    edited 2009-01-11 15:11
    Most of the "high-level" SX/B instructions use the __PARAM variables for their own "internal workings". In other words, commands like PULSOUT, SEROUT, SERIN, division, multiplication use __PARAM1, __PARAM2 etc. If you closely examine the list output, you can see which are used when, but if you are unsure, PRESUME that the values in the PARAM variables will get nuked and will change after instructions like SEROUT.

    The solution is to store params passed to a sub in temp variables so they are not destroyed before you have a chance to use them. Most of the SX/B code posted by JonnyMac and others follow this structure, e.g.

    SEND_BYTE:
      tmpB1 = __PARAM1
      tmpB2 = __PARAM2
      tmpB3 = __PARAM3
      SEROUT RX, Baud, SYNC
      SEROUT RX, Baud, tmpB1
      SEROUT RX, Baud, tmpB2
      SEROUT RX, Baud, tmpB3
      RETURN
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • eagletalontimeagletalontim Posts: 1,399
    edited 2009-01-11 15:21
    My mistake... i found that temp1 and temp2 were changed in another sub.

    EDIT...
    I did change the params to be loaded into variables like you suggested. it works perfect now [noparse]:)[/noparse]
Sign In or Register to comment.