<<Previous

Next>>

5.32. SERIN

SERIN Pin, Mode,{(Qual{,Qual}),} Item{,Item}

Receives one or more items on Pin in standard asynchronous format using 8 data bits, no parity and one stop bit. Mode is one of the following:

Symbol

Value

Baud Rate

Mode

T2400

0

2400

TTL True

T1200

1

1200

T9600

2

9600

T300

3

300

N2400

4

2400

TTL Inverted

N1200

5

1200

N9600

6

9600

N300

7

300

† 9600 baud is an addition to the PICBASIC™ Compiler and is not available on the BASIC Stamp I.

The list of data items to be received may be preceded by one or more qualifiers enclosed within parenthesizes. SERIN must receive these bytes in exact order before receiving the data items. If any byte received does not match the next byte in the qualifier sequence, the qualification process resets (i.e. the next received byte is compared to the first item in the qualifier list). A Qualifier can be a constant, variable or a string constant. Each character of a string is treated as an individual qualifier.

Once the qualifiers are satisfied, SERIN begins storing data in the variables associated with each Item. If the variable name is used alone, the value of the received ASCII character is stored in the variable. If variable is preceded by a pound sign ( # ), then SERIN converts a decimal value in ASCII and stores the result in that variable. All non-digits received prior to the first digit of the decimal value are ignored and discarded. The non-digit character which terminates the decimal value is also discarded.

While single-chip RS-232 level converters are common and inexpensive, the excellent I/O specifications of the PICmicro MCU allow most applications to run without level converters. Rather, inverted input (N9600..N300) can be used is conjunction with a current limiting resistor.

Serin 1,N2400,("A"),B0 'Wait until the character "A" is received serially on Pin1 and put next character into B0

 

5.33. SEROUT

SEROUT Pin, Mode, (Item{,Item})

Sends one or more items to Pin is standard asynchronous format using 8 data bits, no parity and one stop. Mode is one of the following:

Symbol

Value

Baud Rate

Mode

T2400

0

2400

TTL True

T1200

1

1200

T9600

2

9600

T300

3

300

N2400

4

2400

TTL Inverted

N1200

5

1200

N9600

6

9600

N300

7

300

OT2400

8

2400

Open Drain

OT1200

9

1200

OT9600

10

9600

OT300

11

300

ON2400

12

2400

Open Source

ON1200

13

1200

ON9600

14

9600

ON300

15

300

† 9600 baud is an addition to the PICBASIC™ Compiler and is not available on the BASIC Stamp I.

SEROUT supports three different data types which may be mixed and matched freely within a single SEROUT statement.

1)  A string constant is output as a literal string of characters.

2)  A numeric value (either a variable or a constant) will send the corresponding ASCII character. Most notably, 13 is carriage return and 10 is line feed.

3)  A numeric value preceded by a pound sign ( # ) will send the ASCII representation of its decimal value. For example, if W0 = 123, then #W0 (or #123) will send '1', '2', '3'.

While single-chip RS-232 level converters are common and inexpensive, thanks to current RS-232 implementation and the excellent I/O specifications of the PICmicro MCU, most applications don't require level converters. Rather, inverted TTL (N300..N9600) can be used. A current limiting resistor is suggested (RS-232 is suppose to be short-tolerant).

Serout 0,N2400,(#B0,10) 'Send the ASCII value of B0 followed by a linefeed out Pin0 serially
<<Previous

Next>>