'Pong with sockets by Rob faludi 'NOTES by jleblanc: 'LEDs: G b.1, Y b.2, R b.3 'Status LED c.4 'POT a.0 (I THINK) 'This thing does not specifically address the Xport 'Strange? ' We are using a 20Mhz oscillator DEFINE OSC 20 DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 5 TRISA = %11111111 'set all "A" ports to inputs adcon1 = %10000010 'right justify results(?) 'declare variables adcVar var word 'store adc input value pin VAR BYTE 'for looping thru pin numbers numOfPins CON 1 'of max number of pins to scan 'variable for averaging adcAddVar Var Word adcAvgVar Var Word i Var byte ' We communicate with the XPort using 9600 8N1 serial true9600 con 84 timeOut con 50 ' the serial incoming timeout in milliseconds ' Our serial communication pins tx var PORTC.6 rx var PORTC.7 ' Set Debug definitions DEFINE DEBUG_REG PORTB ' the debug port DEFINE DEBUG_BIT 0 ' the debug pin DEFINE DEBUG_BAUD 9600 ' the debug baud rate DEFINE DEBUG_MODE 1 ' Set Debug mode: 0 = true, 1 = inverted ' Our blinking pin for status messages statusPin var PORTC.4 LED var byte OUTPUT statusPin ' Used to read response from the XPort inByte var byte ' Used to send a byte from the XPort outByte Var BYTE ' Track whether or not we are connected to the remote server connected var bit connected = 0 ' Turn on our LED so we know that the startup sequence is going high statusPin ' Wait for the XPort to boot up pause 5000 ' Turn off the status LED while operating LOW statusPin ' Just so we know that we're ready, we'll quickly blink the status LED counter var byte blinkCount var byte ' number of times to blink blinkLight Var Byte ' which portb pin to blink LED = "g" blinkCount = 4 gosub blinkTheLight main: gosub readabyte gosub checkInput gosub sendAnalogValues if inByte <> 0 then debug inByte endif goto main checkInput: if inbyte == "H" then LED = "y" blinkcount = 1 gosub blinkTheLight endif if inbyte == "M" then LED = "r" blinkCount = 3 gosub blinkTheLight endif if inbyte == "W" then LED = "g" blinkCount = 8 gosub blinkTheLight endif if inbyte == "L" then LED = "r" blinkCount = 8 gosub blinkTheLight endif Return readAByte: serin2 rx, true9600, timeOut, noData, [inByte] return noData: inByte = 0 return sendAnalogValues: 'loop thru pins 0 to numOfPins FOR pin = 0 TO numOfPins-1 STEP 1 adcAddVar = 0 adcAvgVar = 0 for i = 0 to 9 step 1 ADCIN pin, AdcVAr 'set adcVar to pin value adcAddVar = adcAddVar + ADCVar NEXT adcAvgVar = adcAddVar/10 outByte = adcAvgVar/4'convert to byte serout2 tx, true9600, [outByte] NEXT return blinkTheLight: counter = 0 while counter < blinkCount select case LED case "g" high portb.1 pause 100 low portb.1 pause 100 case "y" high portb.2 pause 100 low portb.2 pause 100 case "r" high portb.3 pause 100 low portb.3 pause 100 end select counter = counter + 1 wend return