May 02, 2024, 01:17:17 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Zombie Thrasher Code for the SX

Started by cmallsop, October 12, 2012, 01:18:21 PM

Previous topic - Next topic

cmallsop

Does anyone have simple zombie thrasher code for the SX board? I'm looking for code that will drive two pneumatic cylinders, no music, lights or anything else. I'm looking for a 1 minute cycle with a 10 second rest. Unfortunately the Prop-1 code won't work on the SX board and I'm just not much of a programmer anymore.

Thanks in advance for your help!

Mark Allsop
Vampyre Manor
Mark Allsop
Vampyre Manor

JonnyMac

Wow... I haven't written and SX code in a long time, so this really took some cleaning of the cobwebs.  I've got a Prop-1 Trainer connected to my Prop-SX (on the P8..P15 group).  P14 is used as the trigger input -- for normal use put the P14 SETUP jumper in the DN position.

Note that you may not have the SX/B compiler installed as I do so I have attached the compiled program (.SXH file). Use the Run -> Device dialog to load the .SXH file and program it into your Prop-SX.

' =========================================================================
'
'   File...... Casa_Fear_Zombie.SXB
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started... 15 OCT 2012
'   Updated...
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


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

ID              "CasaFear"

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


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

UnusedRC7       PIN     RC.7 INPUT              ' SETUP = DN

Trigger         PIN     RC.6 INPUT              ' SETUP = DN

UnusedRC5       PIN     RC.5 INPUT
UnusedRC4       PIN     RC.4 INPUT
UnusedRC3       PIN     RC.3 INPUT
UnusedRC2       PIN     RC.2 INPUT

LShoulder       PIN     RC.1 OUTPUT             ' V+/OUT9
RShoulder       PIN     RC.0 OUTPUT             ' V+/OUT8

UnusedRB        PIN     RB   INPUT


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

IsOn            CON     1
IsOff           CON     0


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

lottery         VAR     Byte                    ' random #
valves          VAR     Byte
last            VAR     Byte

xTimer          VAR     Word                    ' for timing
delay           VAR     Word

tmpW1           VAR     Word                    ' for subs & funcs


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_MS        SUB     1, 2                    ' delay in milliseconds

RANDOMIZE       FUNC    1, 1


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

Start:
  LShoulder = IsOff                             ' clear cylinders
  RShoulder = IsOff

  DELAY_MS 10_000                               ' (re)trigger delay

  xTimer = 0                                    ' restart debounce timer

Check_Trigger:
  lottery = RANDOMIZE lottery                   ' re-stir random #
  DELAY_MS 1
  IF Trigger = IsOff THEN
    xTimer = 0
  ELSE
    INC xTimer
  ENDIF
  IF xTimer < 100 THEN Check_Trigger

Jump:
  LShoulder = IsOn                              ' jump
  RShoulder = IsOn
  DELAY_MS 1000

  xTimer = 0                                    ' reset

Thrasher:
  lottery = RANDOMIZE lottery                   ' re-stir
  valves = lottery & %00010010                  ' isolate valve bits

  IF valves = last THEN Thrasher                ' no repeats
    last = valves                               ' save for next cycle

  LShoulder = valves.1                          ' update outputs
  RShoulder = valves.4

  lottery = RANDOMIZE lottery
  delay = lottery + 100                         ' randomze delay
  DELAY_MS delay
  xTimer = xTimer + delay
  IF xTimer < 60000 THEN
    GOTO Thrasher
  ELSE
    GOTO Start
  ENDIF


' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

' Use: DELAY_MS mSecs
' -- 'mSecs' is delay in milliseconds, 1 - 65535

SUB DELAY_MS
  mSecs         VAR     __WPARAM12

  \ SB    __PARAMCNT.1                          ' skip if word passed
  \ CLR   mSecs_MSB                             ' clear MSB if byte

  PAUSE mSecs
  ENDSUB

' -------------------------------------------------------------------------

' Use: result = RANDOMIZE seed
'
FUNC RANDOMIZE
  ASM
    MOV   __PARAM2, #3                          ' run 3x

RND_Loop:
    MOV   W, __PARAM1                           ' RANDOM __PARAM1
    ADD   __PARAM1, W
    ADD   __PARAM1, W
    ADD   __PARAM1, W
    ADD   __PARAM1, W
    ADD   __PARAM1, #123
    DJNZ  __PARAM2, @RND_Loop
  ENDASM
  ENDFUNC

' -------------------------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office