Positron Compiler Documentation

Serin - Serout Declare.

Source: Positron8 Compiler User Manual, PDF page 438

If communications are with existing software or hardware, its speed and mode will determine the choice of Baud rate and mode. In general, 7-bit/even-parity (7E) mode is used for text, and 8-bit/no-parity (8N) for byte-oriented data. Note: the most common mode is 8-bit/no-parity, even when the data transmitted is just text. Most devices that use a 7-bit data mode do so in order to take advantage of the parity feature. Parity can detect some communication errors, but to use it you lose one data bit. This means that incoming data bytes transferred in 7E (even-parity) mode can only represent values from 0 to 127, rather than the 0 to 255 of 8N (no-parity) mode.

The compiler's serial commands Serin and Serout have the option of still using a parity bit with 4 to 8 data bits. This is through the use of a Declare: -

With parity disabled (the default setting): -

Declare Serial_Data = 4 ' Set Serin and Serout data bits to 4
Declare Serial_Data = 5 ' Set Serin and Serout data bits to 5
Declare Serial_Data = 6 ' Set Serin and Serout data bits to 6
Declare Serial_Data = 7 ' Set Serin and Serout data bits to 7
Declare Serial_Data = 8 ' Set Serin and Serout data bits to 8 (default)

With parity enabled: -

Declare Serial_Data = 5 ' Set Serin and Serout data bits to 4
Declare Serial_Data = 6 ' Set Serin and Serout data bits to 5
Declare Serial_Data = 7 ' Set Serin and Serout data bits to 6
Declare Serial_Data = 8 ' Set Serin and Serout data bits to 7 (default)
Declare Serial_Data = 9 ' Set Serin and Serout data bits to 8

Serial_Data data bits may range from 4 bits to 8 (the default if no Declare is issued). Enabling parity uses one of the number of bits specified.

Declaring Serial_Data as 9 allows 8 bits to be read and written along with a 9th parity bit.

Parity is a simple error-checking feature. When a serial sender is set for even parity (the mode the compiler supports) it counts the number of 1s in an outgoing byte and uses the parity bit to make that number even. For example, if it is sending the 7-bit value: 0b0011010, it sets the parity bit to 1 in order to make an even number of 1s (four). The receiver also counts the data bits to calculate what the parity bit should be. If it matches the parity bit received, the serial receiver assumes that the data was received correctly. Of course, this is not necessarily true, since two incorrectly received bits could make parity seem correct when the data was wrong, or the parity bit itself could be bad when the rest of the data was correct.

Many systems that work exclusively with text use 7-bit/ even-parity mode. For example, to receive one data byte through bit-0 of PORTA at 9600 Baud, 7E, inverted: