February 12, 2005

Code to set up and test xport/pic communication

' based on Tom Igoe code

' variables and constants for the serial port:
dataByte var byte
dataByte2 var byte

init Var Byte
init = 0

tx var portc.6
rx var portc.7
xportRx var portc.0
xportTx var portc.1
xportDTR var portc.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

led1 VAR portC.4
led2 VAR portC.3

Pause 1000 ' Wait a second at startup

' take DTR high so Xport doesn't disconnect when we first connect:
HIGH xportDTR

low led1
High led2 'on light

main:
if init =1 then
serin2 rx, inv9600, [dataByte]
else
serin2 xportRx, non9600, [dataByte]
endif
' parse the data:
gosub checkByte

goto main


checkByte:
if init = 0 Then
if dataByte = 55 or dataByte = 73 then
init = 1
serout2 tx, inv9600, ["swap should happen", 10, 13]
endIF
Else
if dataByte = 126 then
init = 0
dataByte = 57
serout2 tx, inv9600, ["swap back should happen", 10, 13]
Endif
endIF
if dataByte > 47 then
' convert the ascii value of 0-9 to a numeric value
' (ascii "0" = 48)
dataByte2 = dataByte - 48

' if we get "9", turn on light.
if dataByte2 = 9 then
' flashy = 1
High led1
endif
if dataByte2 = 8 then
'flashy = 0
Low led1
endif
' if we get a 0, then disconnect
' by taking the Lantronix device DTR low:
if dataByte2 = 0 then
low xportDTR
pause 300
high xportDTR
endif
' send all bytes straight out without parsing:
serout2 xportTx, non9600, [dataByte, 13]
serout2 tx, inv9600, [dataByte, 10, 13]
endif
return

Posted by William Blaze at February 12, 2005 04:13 PM | TrackBack