GOSUB Example | Syntax |
' ------------------------------------------------------------------------- ' 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,
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? <A HREF="http://sxlist.com/techref/parallax/sxb/sxb/gosub_ex.htm"> GOSUB Example</A> |
Did you find what you needed? |
Welcome to sxlist.com!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! |
.