![]() ZBasic System Library
278
ZBasic Microcontrollers
Type
Subroutine
Invocation
SerialOut(data, pin, baudRate)
Parameter
Method
Type
Description
data
ByVal
Byte or String
The data to be output.
pin
ByVal
Byte
The pin on which to output the data.
baudRate
ByVal
integral
The baud rate for the serial output.
Discussion
This subroutine outputs the data byte, or the characters of the String, at the specified baud rate on the
specified pin. The pin must have been previously configured to be an output in either the high state (for
non-inverted data) or the low state (for inverted data). The initial state of the pin determines whether the
data will be sent in non-inverted or inverted mode.
The characters transmitted in 8-N-1 format, i.e. 8 data bits, no parity, 1 stop bit. The transmission of each
byte is performed with interrupts disabled, comprising an interval of approximately (10 / baudRate)
seconds, also known as the character time. Consequently, higher baud rates are preferable to lower
baud rates. The theoretical maximum baud rate varies by processor frequency and is expressed as
(F_CPU / 25) while the theoretical minimum baud rate is (F_CPU / 262165). Note, particularly, that if the
RTC is enabled and the character time is greater than approximately 1.5 times the RTC interrupt interval,
the RTC may lose time. At 14.7MHz with a 1024Hz RTC interrupt, the minimum standard baud rate that
avoids missing RTC interrupts would be 9600.
The serial output mechanism is the same as that used when Option Console is specified with a pin
designator (which pin is available via the compile-time constant Option.ConsolePin). See the
description of Option Console in the ZBasic Language Reference Manual for more Information.
This subroutine is useful primarily on devices that have no hardware UARTs and/or in cases where you
do not want to dedicate a timer for the software UART channels, leaving it free for other purposes.
Example
Const pin as Byte = A.0
Const str as String = "Hello, world!" & Chr(&H0d) & Chr(&H0a)
' configure the pin as an output, send a string
Call PutPin(pin, zxOutputHigh) ' non-inverted idle state
Call SerialOut(str, pin, 38400) ' send string chars at 38.4K baud
Compatibility
This subroutine is not available in BasicX compatibility mode or on VM-based devices.
See Also
|