Navigation bar
  Start Previous page
 84 of 323 
Next page End  

ZBasic System Library
74
ZX Microcontroller Family
DefineCom
Type
Subroutine
Invocation
DefineCom(channel, rxPin, txPin, flags)
DefineCom(channel, rxPin, txPin, flags, stopBits)
Parameter
Method
Type
Description
channel
ByVal
Byte
The serial channel being defined.
rxPin
ByVal
Byte
The pin which will serve as the receive line.
txPin
ByVal
Byte
The pin which will serve as the transmit line.
flags
ByVal
Byte
Configuration flags.  See the discussion below.
stopBits
ByVal
Byte
The desired number of stop bits.
Discussion
This routine configures a serial channel, preparing it to be opened using OpenCom().  If the specified
channel is already open, this routine does nothing.  Likewise, there is no effect if the specified channel is
invalid (see the ComChannels() routine) or if either of the rxPin and txPin parameters are invalid or
both are zero.  Note that either rxPin or txPin may be zero, allowing you to define a transmit-only or
receive-only serial channel.
If the specified channel is a hardware UART (e.g. Com1), the rxPin and txPin parameters must both
be zero.  Otherwise, if they are valid, the pins specified by rxPin and txPin are automatically
configured as input and output, respectively.  However, if the rxPin and txPin parameter values are
equal and non-zero, the pin is initially configured as an input to support half-duplex, bussed operation.  In
this mode, the the pin will be made an output when transmitting a zero bit if configured for non-inverted
operation or when transmitting a one bit if configured for inverted operation.  A pull-up resistor (non-
inverted mode) or pull-down resistor (inverted mode) is required for bussed operation since the pin will
only be actively driven in one of the two output states.
The flags parameter contains several bit fields used to specify some of the details of the operation of
the serial channel.
Serial Channel Configuration Flag Values
Function
Hex Value
Bit Mask
Inverted Logic¹
&H80
1x xx xx xx
Non-inverted Logic
&H00
0x xx xx xx
Ignore Parity Bit
&H40
x1 xx xx xx
Even Parity
&H30
xx 11 xx xx
Odd Parity
&H20
xx 10 xx xx
No Parity
&H00
xx 00 xx xx
7-bit Data
&H07
xx xx 01 11
8-bit Data
&H08
xx xx 10 00
7-bit Data, bussed mode¹
&H0b
xx xx 10 11
8-bit Data, bussed mode¹
&H0c
xx xx 11 00
   ¹ Applicable only to software-based channels (3-6).
The remaining bit values are currently undefined but may be employed in the future.
When Non-inverted Logic is selected, the idle state of the transmit line will be logic 1.  When a character
transmission is begun, a “start bit” of logic zero will be sent for one bit time (the inverse of the baud rate). 
Next the data bits are sent, each for one bit time, beginning with the least significant bit and continuing
through the eighth data bit or parity bit as the case may be.  Finally, one or more “stop bits” of logic one
are sent, each for one bit time.  With Inverted Logic, each of these elements is complemented – the idle
state of the transmit line is logic 0.
Previous page Top Next page