As an example, this Vixen driver breaks P15 from the outputs to be used an an input. When the switchis off the outputs are cleared and the servos are centered; when the switch is on the program will accept data from Vixen -- no matter where Vixen is in its cycle (so be careful).
Note that the DIRS register has been modified to make P15 an input; you can write to it all day long, when in input mode that doesn't matter.
' =========================================================================
'
' File...... Vixen.BS2
' Purpose... Simple Vixen interface for Prop-2_8s8d.DLL driver
' Author.... Jon Williams, EFX-TEK
' Copyright (c) 2007 EFX-TEK
' E-mail.... jwilliams@efx-tek.com
' Started...
' Updated... 14 MAY 2007
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
'
' This program serves as a slave interface to Vixen (www.vixenlights.com),
' when using the Prop-2_8s8d.DLL driver.
'
' Connect to PC using the Prop-2 programming port.
'
' Note: Set the Vixen Prop-2 driver baud rate to 9600 (this is the fastest
' practical baud for using the WAIT modifier of SERIN which is required
' to maintain sync with Vixen packets).
'
' Note: The best Vixen Event Period (Tools\Preferences\EventPeriod) is
' 40 ms; periods shorter will cause some packets to be missed by the Prop-2
' while periods longer may result in "rough" servo movement.
'
' Remove the SETUP jumpers from P12..P15.
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
RX CON 16 ' use programming port
Enabled PIN 15 ' P15; SETUP = DN
DigOuts VAR OUTH ' use P8..P14
Servos VAR OUTL ' use P0..P7
Servo8 CON 7
Servo7 CON 6
Servo6 CON 5
Servo5 CON 4
Servo4 CON 3
Servo3 CON 2
Servo2 CON 1
Servo1 CON 0
' -----[ Constants ]-------------------------------------------------------
T2400 CON 396
T9600 CON 84 ' recommended baud rate
T19K2 CON 32
T38K4 CON 6
SevenBit CON $2000
Inverted CON $4000
Open CON $8000
Baud CON T9600 ' use 9600!
Yes CON 1
No CON 0
' -----[ Variables ]-------------------------------------------------------
idx VAR Byte ' servo index
pos1 VAR Byte ' servo position values
pos2 VAR Byte
pos3 VAR Byte
pos4 VAR Byte
pos5 VAR Byte
pos6 VAR Byte
pos7 VAR Byte
pos8 VAR Byte
' -----[ Initialization ]--------------------------------------------------
Reset:
OUTS = $0000 ' clear all pins
DIRS = $7FFF ' all outputs
FOR idx = 0 TO 7 ' center servos to start
pos1(idx) = 150
NEXT
GOSUB Refresh_Servos
IF Enabled = No THEN Reset ' wait for enabled input
' -----[ Program Code ]----------------------------------------------------
Main:
DO WHILE (Enabled = Yes)
SERIN RX, Baud, 40, No_Serial,
[WAIT ("VXN"), DigOuts,
pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8]
No_Serial:
GOSUB Refresh_Servos
LOOP
GOTO Reset
' -----[ Subroutines ]-----------------------------------------------------
Refresh_Servos:
PULSOUT Servo1, (pos1 * 5)
PULSOUT Servo2, (pos2 * 5)
PULSOUT Servo3, (pos3 * 5)
PULSOUT Servo4, (pos4 * 5)
PULSOUT Servo5, (pos5 * 5)
PULSOUT Servo6, (pos6 * 5)
PULSOUT Servo7, (pos7 * 5)
PULSOUT Servo8, (pos8 * 5)
RETURN