February 12, 2005

incomplete code for alyssa's side

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 2/7/2005                                          *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
' 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
dataByte2 var byte
tx var portc.6
rx var portc.7
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


' 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
input portc.4
qproxVar var byte

'set data in on c4
high portc.4
pause 1000
low portc.4

'set data in on c.5
high portc.5
pause 1000
low portc.5

main:
qproxVar = portc.4
debug "qprox = ", DEC qproxVar, 10, 13
'read the ADC value:
adcin 0, ADCvar
' check for incoming serial data from the net:
serin2 xportRx, non9600, [dataByte]
' parse the data:
gosub checkByte
goto main

checkByte:
if dataByte > 47 then
' convert the ascii value of 0-9 to a numeric value
' (ascii "0" = 48)
dataByte2 = dataByte - 48

' if the number is between 1 and 8, light an LED:
if dataByte2 > 0 && dataByte2 <= 8 then
' the dcd command takea a number and
' converts it to the position of a bit in a byte:
portb = dcd (databyte2 - 1)
endif

' if we get "9", send the ADC message.
if dataByte2 = 9 then
serout2 xportTx, non9600, [DEc 126, 10, 13]
serout2 tx, inv9600, [DEc 126, 10, 13]
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
endif
' send all other bytes straight out without parsing:
serout2 xportTx, non9600, [dataByte, 10, 13]
serout2 tx, inv9600, [dataByte, 10, 13]
return



Posted by William Blaze at February 12, 2005 10:46 PM | TrackBack