'*** NOTE: CIRCUIT DIAGRAM FOR COMMUNICATION CABLE *** '*** IS AT THE BOTTOM OF THIS FILE *** 'use this program to test your communication cable - 'each time the stamp gets a particular input (the number 100) 'it replies with the next number as it counts up to 400 and 'back down again. SerInPin PIN 0 'serial IN pin (RXD - at the other end: TXD) SerOutPin PIN 1 'serial OUT pin (TXD - at the other end: RXD) SerInData VAR BYTE 'number to match to incoming data SerWait CON 50 'ms to wait for input before timing out N9600 CON 16468 'BS2 baudmode values: 16468/9600, 16416/19200, 16390/38400 'See SEROUT in the Basic Stamp manual for details. myCount VAR WORD 'counter myCount = 0 upCount VAR BIT 'flag to count up or down upCount = 1 waitCounter VAR BYTE 'counter to print waiting message to debug window waitCounter = 0 DEBUG CR,"Program starting ...",CR Main_Loop: 'if we're not getting any input, print a message every few seconds waitCounter = waitCounter + 1 IF waitCounter >= 200 THEN DEBUG "Waiting for serial input ...",CR waitCounter = 0 ENDIF 'read serial in, loop if nothing is received by timeout SERIN SerInPin,N9600,SerWait,Main_Loop,[SerInData] IF serInData = 100 THEN waitCounter = 0 GOSUB The_Count 'do counting subroutine SEROUT SerOutPin,N9600,[DEC myCount,CR] 'send current value DEBUG DEC myCount,CR 'print to debug window ELSE DEBUG "Received: ",DEC SerInData,CR 'got something, but not 100 ENDIF GOTO Main_Loop The_Count: IF myCount < 400 AND upCount = 1 THEN 'counting up (0 to 400) myCount = myCount+1 ELSEIF myCount > 0 AND upCount = 0 THEN 'counting down (400 to 0) myCount = myCount - 1 ELSEIF myCount = 400 THEN upCount = 0 'switch from up to down myCount = 399 ELSEIF myCount = 0 THEN upCount = 1 'switch from down to up myCount = 1 ENDIF RETURN 'SERIAL CABLE DIAGRAM: '(use 9 pin female D-Sub connector, Radio Shack #2761538) ' ' +---------SERIAL OUT [PIN 1] ' | +--22K--SERIAL IN [PIN 0] ' | | +---GND ' | | | ' 1 2 3 4 5 ' \-----------/ ' \o o o o o/ ' \o o o o/ ' \-----/ ' 6 7 8 9 ' 'diagram represents back of connector, facing solder terminals. ' '