'{$STAMP BS2} '{$PBASIC 2.5} ' 2008 mlab.taik.fi/paja ' Receiving data from a Serial port ' ---[ I/O Definitions ]--- pLED PIN 15 pSerial CON 16 ' ---[ Variables ]--- nCount VAR NIB bIndex VAR BYTE ' ---[ Constants ]--- cBS2 CON $100 ' x 1.0, cycle adjustment (for ms) ' ---[ Initialization ]--- DEBUG CLS, "Receiving data from a Serial port", CR ' ---[ Main Code ]--- Main: DO ' DEBUGIN baudmode is 84 (9800 baudrate, 8bit, no-parity, 1 Stop bits) ' ' SERIN Rpin{\Fpin}, Baudmode, {Plabel, } {Timeout, Tlabel, } [InputData] ' Rpin: pin number (0-16). Pin16 is dedicated serial-output pin ' TO RS232 OR USB. Sperifies the I/O pin through which the serial data ' will be received. ' Fpin: optional pin number (0-15). Indicates flow control status on. ' Baudmode: 0-65535. specifies serial timing and configuration. ' See SEROUT in BASIC Stamp Synbtax and Reference Manual ' Plabel: Optional label. Indicates if a praity error. This should only be ' provided if Buadmode indicates 7bits, and even parity. ' Timeout: Optional (0-65535). Tells SERIN how long to wait for incoming data. ' Tlabl: Optional label. Must be provided along with Timeout. Indicats ' where the program should go after timeout. ' InputData: Tells SERIN what to do with incoming data. ' See SEROUT in BASIC Stamp Synbtax and Reference Manual DEBUGIN DEC nCount ' = SERIN pSerial, 84, [DEC nCount] DEBUG "retun: ", DEC nCount, CR FOR bIndex = 1 TO nCount STEP 1 HIGH pLED PAUSE 200 LOW pLED PAUSE 300 NEXT LOOP END