' Serial out to PC is on pin RC6
' serial in from PC is on pin RC7
' serial out to Lantronix device is on RD1
' serial in from Lantronix device is on RD0
' Lantronix device DTR pin is on RD2
' note: Lantronix device must have DisconnectMode set to 0x80
' in order to disconnect using DTR pin. ' an analog sensor is on pin RA0
' pins RB0 through RB7 have LEDs on them.
' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
' variables and constants for the serial port:
dataByte var byte
tx var portc.6
rx var portc.7
vibePin VAR portb.7
myButton Var portc.5
xportTx var portd.1
xportRx var portd.0
xportDTR var portd.2
inv9600 con 16468 ' baudmode for serin2 and serout2: 9600 8-N-1
inverted
non9600 con 84 ' baudmode for serin2 and serout2: 9600 8-N-1 non-
inverted
' general-purpose counter:
i var byte
'variables for ADC:
ADCvar var word ' Create variable to store result
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
TRISB = %00000000 ' set all the pins of PORTB to output
input portc.5
OUTPUT PORTD.4
vibeRun Var BYTE 'DO WE HAVE THE VIBE?
vibeRun = 0
vibePin = 0
myDataByte Var byte
thierData var byte
myDataByte = 65 ' 0 = vibe is here
thierData = 0
counterGo Var word
counterGo = 0
' blink an LED on startup:
high portb.0
pause 1000
low portb.0
' take DTR high so Xport doesn't disconnect when we first connect:
HIGH xportDTR
Pause 1000 ' Wait a second at startup
main:
' check for incoming serial data from the net:
serin2 xportRx, non9600, 20, nextSub, [dataByte]
nextSub:
if dataByte = 65 then
thierData = 65
'myDataByte = 0
'vibePin = 1 'they are off
HIGH portb.7
vibeRun = 1 ' i have the vibe
endif
if dataByte = 0 Then
'vibePin = 0
'myDataByte = 65
low portb.7
thierData = 0 ' i am off
vibeRun = 0 ' they have the vibe
endif
'output 65 = they have the vibration
'outout 0 = we have the vibration
if vibeRun =1 Then 'do i have the Vibe?
myDataByte = 0
if myButton = 1 then 'checks if button is pressed
vibeRun = 0 ' turn off vibe
vibePin = 0
myDataByte = 65 ' set output to say I they should
get the Vibe
'set off timer'
counterGo = 1
i = 1
endif
if myButton = 0 then
'vibePin = 1 ' set pin high
HIGH portb.7 ' turn on vibe pin if button not press
and we have vibe
'vibeRun = 1 ' set Varible on
endif
Endif
if vibeRun = 0 then
'myDataByte = 65 ' set output to say I DONT have the vibe
serout2 xportTx, non9600, [MYdataByte]
SEROUT2 PORTD.4, inv9600, ["TCP Databyte: ", DEC myDataByte]
endif
if MydataByte = thierData then
myDataByte = 65
endif
'output 65 = they have the vibration
'outout 0 = we have the vibration
'OUTPUT TO XPORT
if counterGo >= 1 then
low portb.7
'send A to xport
myDataByte = 65
serout2 xportTx, non9600, [MYdataByte]
i = i + 1
SEROUT2 PORTD.4, inv9600, [" I : ", DEC I, "COUNTERGO = ", DEC counterGo]
SEROUT2 PORTD.4, inv9600, ["IN COUNTER LOOK myDataByte: ", DEC myDataByte]
'counterGo = counterGo + 1
if i>=30 then
counterGo = 0
endif
endif
serout2 xportTx, non9600, [MYdataByte]
'serout2 xportTx, non9600, [myDataByte]
'send out 65 or 0 a bunch of times
'send out to HyperTerm
'SEROUT2 PORTD.4, inv9600, ["TCP Databyte: ", DEC myDataByte]
goto main |