' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Demonstrates FOR-NEXT loops in SX/B with a "ping-pong" LED display.
' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "FOR-NEXT"
' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------
LEDs VAR RB ' LED outputs
TRIS_LEDs VAR TRIS_B
' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
idx VAR Byte ' loop counter
' =========================================================================
PROGRAM Start
' =========================================================================
' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------
Start:
TRIS_LEDs = %00000000 ' make LED pins outputs
Main:
DO
FOR idx = 0 TO 5 ' loop 7 times
LEDs = 1 << idx ' LEDs = 1, 2, 4, 8, ...
PAUSE 100 ' pause 100 ms
NEXT
FOR idx = 7 TO 1 STEP -1 ' loop 7 times
LEDs = 1 << idx ' LEDs = 128, 64, 32 ...
PAUSE 100 ' pause 100 ms
NEXT
LOOP ' repeat forever