Syntax

           

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Controls eight channels of lights using RB.  Sequence is selected by
' switches connected to RA.0 and RA.1.  The delay between steps is fixed
' by a constant, but could easily be modified to be variable by using 
' RCTIME. 

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

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000
ID              "BRANCH"

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

Select          VAR     RA                      ' bits 0 and 1
TRIS_Sel        VAR     TRIS_A
Lights          VAR     RB
TRIS_Lights     VAR     TRIS_B

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

StepDelay       CON     100                     ' 100 ms between steps

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

choice          VAR     Byte                    ' selected sequence
maxSteps        VAR     Byte                    ' steps in sequence
idx             VAR     Byte                    ' step pointer                               

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

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

Start:
  Lights = %00000000                            ' clear lights
  TRIS_Lights = %00000000                       ' make lights outputs

Main:
  PAUSE StepDelay                               ' inter-step delay
  choice = Select & %0011                       ' get show 
  BRANCH choice, Show_0, Show_1, Show_2, Show_3
  GOTO Main

Show_0:
  READ Pattern0, maxSteps                       ' get steps in sequence
  IF idx <= maxSteps THEN                       ' check idx range
    READ Pattern0 + idx, Lights                 ' get step pattern
    INC idx                                     ' point to next step
  ELSE
    idx = 1                                     ' reset idx if needed
  ENDIF
  GOTO Main

Show_1:
  READ Pattern1, maxSteps
  IF idx <= maxSteps THEN
    READ Pattern1 + idx, Lights
    INC idx
  ELSE
    idx = 1
  ENDIF
  GOTO Main

Show_2:
  READ Pattern2, maxSteps
  IF idx <= maxSteps THEN
    READ Pattern2 + idx, Lights
    INC idx
  ELSE
    idx = 1
  ENDIF
  GOTO Main

Show_3:
  READ Pattern3, maxSteps
  IF idx <= maxSteps THEN
    READ Pattern3 + idx, Lights
    INC idx
  ELSE
    idx = 1
  ENDIF
  GOTO Main

' =========================================================================
' User Data
' =========================================================================

Pattern0:
  DATA  8                                       ' steps in sequence
  DATA  %00000001                               ' sequence values
  DATA  %00000010
  DATA  %00000100
  DATA  %00001000
  DATA  %00010000
  DATA  %00100000
  DATA  %01000000
  DATA  %10000000

Pattern1:
  DATA  10
  DATA  %00000000
  DATA  %10000000
  DATA  %11000000
  DATA  %01100000
  DATA  %00110000
  DATA  %00011000
  DATA  %00001100
  DATA  %00000110
  DATA  %00000011
  DATA  %00000001

Pattern2:
  DATA  5
  DATA  %00000000
  DATA  %00011000
  DATA  %00100100
  DATA  %01000010
  DATA  %10000001 

Pattern3:
  DATA  5
  DATA  %11111111 
  DATA  %01111110
  DATA  %00111100
  DATA  %00011000
  DATA  %00000000