Example

  SEROUT Pin, BaudMode, Value

Function
Transmit asynchronous serial byte (e.g., RS-232).

Quick Facts
  FREQ = 4 MHz FREQ = 20 MHz FREQ = 50 MHz
 Maximum Baud Rate 57600 460800 > 921600
 Baud Modes T (true), N (inverted), OT (open, true), ON (open, inverted)

Explanation
Transmit asynchronous serial byte at the selected baud rate and mode using no-parity, 8-data bits, and 1-stop bit .

  SEROUT RA.0, T9600, "A"

In the example above, the SX will transmit the letter "A" (decimal 65) to an external device at 9600 baud, in true mode on pin RA.0. Since SEROUT requires a substantial amount of assembly code a good way to save program space is by placing SEROUT in a subroutine.

For example:

TX_CHAR:
  temp1 = __PARAM1                              ' save byte to send
  temp2 = __PARAM2                              ' save number of repeats
  
  DO WHILE temp2 > 0
    SEROUT Sio, Baud, temp1                     ' send the byte
    DEC temp2                                   ' update count
  LOOP
  RETURN

This subroutine takes two parameters: the first is the byte to transmit and the second is the number of times to transmit that byte. By using the second parameter sending "**********" is as easy as (when the subroutine is declared with SUB):

  TX_CHAR "*", 10                               ' send "**********"

Note: Interrupts will interfere with the proper operation of SEROUT and, in most cases, should be disabled before the SEROUT instruction is used. If the interrupt is short and designed to run the same number of cycles under any condition, the EffectiveHz  parameter of FREQ may be used.


Related instruction: SERIN
Related projects: Serial LCD and RFID Reader Interface