Syntax
please dont rip this site

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Demonstrates GOSUB with parameter passing across page boundaries. Note
' that the GOSUB keyword is no longer required when using version 1.2
' syntax (SUB definition).  Note, too, that the INVERT subroutine behaves
' like a function by returning a value.


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000


' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------

LEDs            VAR     RB
TRIS_LEDs       VAR     TRIS_B


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

Speed           CON     150                     ' loop delay control


' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

zigzag          VAR     Byte                    ' zigzag controller

temp1           VAR     Byte                    ' work vars
temp2           VAR     Byte


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


' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------

DELAY           SUB     1, 2                    ' base { x multiplier }
INVERT          SUB     1                       ' register address


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  TRIS_LEDs = %00000000                         ' make LEDs pins outputs
  zigzag = %00000001

Main:
  DO
    LEDs = INVERT zigzag                        ' invert LED pattern
    DELAY Speed                                 ' loop delay
    zigzag = zigzag << 1                        ' shift bit left
  LOOP UNTIL zigzag = %10000000

  DO
    LEDs = INVERT zigzag
    DELAY Speed
    zigzag = zigzag >> 1                        ' shift bit right
  LOOP UNTIL zigzag = %00000001
 
  GOTO Main


' -------------------------------------------------------------------------
' Subroutines Code
' -------------------------------------------------------------------------

' Use: DELAY base {, multiplier }
' -- pauses 'base' * (optional) 'multiplier' milliseconds

DELAY:
  temp1 = __PARAM1                              ' capture parameters
  IF __PARAMCNT = 1 THEN                        ' if no multiplier
    temp2 = 1                                   ' - set to 1
  ELSE
    temp2 = __PARAM2
  ENDIF
  IF temp1 > 0 THEN
    IF temp2 > 0 THEN 
      PAUSE temp1 * temp2                       ' do the pause
    ENDIF
  ENDIF
  RETURN


' Use: aVar = INVERT theByte
' -- inverts the bits in 'theByte'

INVERT:
  temp1 = __PARAM1                              ' get current value
  temp1 = ~temp1                                ' invert the bits
  RETURN temp1                                  ' return value to caller

file: /Techref/parallax/sxb/sxb/gosub_ex.htm, 4KB, , updated: 2006/4/10 14:47, local time: 2025/5/16 05:12,
TOP NEW HELP FIND: 
18.188.100.179:LOG IN

 ©2025 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/techref/parallax/sxb/sxb/gosub_ex.htm"> GOSUB Example</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .