Positron Compiler Documentation

Rsout

Source: Positron16 Compiler User Manual, PDF page 244

Syntax

Rsout Item {, Item... }

Overview

Send one or more Items to a predetermined pin at a predetermined Baud rate in standard asynchronous format using 8 data bits, no parity and 1 stop bit (8N1). The pin is automatically made an output.

Parameters

Item may be a constant, variable, expression, or string list. There are no operands as such, instead there are modifiers. For example, if an at sign'@' precedes an Item, the ASCII representation for each digit is transmitted.

The modifiers are listed below: -

Modifier

Operation

Bin{1..32}

Send binary digits

Dec{1..10}

Send decimal digits

Hex{1..8}

Send hexadecimal digits

Sbin{1..32}

Send signed binary digits

Sdec{1..10}

Send signed decimal digits

Shex{1..8}

Send signed hexadecimal digits

Ibin{1..32}

Send binary digits with a preceding '%' identifier

Idec{1..10}

Send decimal digits with a preceding '#' identifier

Ihex{1..8}

Send hexadecimal digits with a preceding '$' identifier

ISbin{1..32}

Send signed binary digits with a preceding '%' identifier ISdec{1..10} Send signed decimal digits with a preceding '#' identifier

IShex{1..8}

Send signed hexadecimal digits with a preceding '$' identifier

Rep c\n

Send character c repeated n times

Str array\n

Send all or part of an array Cstr Label Send string data defined in code memory.

The numbers after the Bin, Dec, and Hex modifiers are optional. If they are omitted, then the default is all the digits that make up the value will be displayed.

If a floating point variable is to be displayed, then the digits after the Dec modifier determine how many remainder digits are send. i.e. numbers after the decimal point.

Dim MyFloat as Float
MyFloat = 3.145
Rsout Dec2 MyFloat
                      ' Send 2 values after the decimal point

The above program will transmit the ASCII representation of the value 3.14

If the digit after the Dec modifier is omitted, then 3 values will be displayed after the decimal point.

Dim MyFloat as Float
MyFloat = 3.1456
Rsout Dec MyFloat
                      ' Send 3 values after the decimal point

The above program will send 3.145

There is no need to use the Sdec modifier for signed floating point values, as the compiler's Dec modifier will automatically display a minus result: -

Dim MyFloat as Float
MyFloat = -3.1456
Rsout Dec MyFloat
                      ' Send 3 values after the decimal point

The above program will transmit the ASCII representation of the value -3.145

Example

  Device = 24HJ128GP502
                                     ' Select the device to compile for
  Declare Xtal = 16
  Dim Var1 as Byte
  Dim MyWord as Word
  Dim MyDword as Dword
  Rsout "Hello World"
                                     ' Display the text "Hello World"
  Rsout "Var1= ", Dec Var1
                                     ' Display the decimal value of Var1
  Rsout "Var1= ", Hex Var1
                                     ' Display the hexadecimal value of Var1
  Rsout "Var1= ", Bin Var1
                                     ' Display the binary value of Var1
  Rsout "MyDword= ", Hex6 MyDword  ' Display 6 hex chars of a Dword variable

Example 3 will produce the text "$-1234" on a serial terminal.

The Cstr modifier is used in conjunction with flash memory strings. The Dim as Flash8 directive is used for initially creating the string of characters: -

Dim String1 as Flash8 = "Hello World", 0

The above line of case will create, in flash memory, the values that make up the ASCII text "Hello World", at address String1. Note the null terminator after the ASCII text. Null terminated means that a zero (null) is placed at the end of the string of ASCII characters to signal that the string has finished.

To display, or transmit this string of characters, the following command structure could be used:

Rsout Cstr String1

The label that declared the address where the list of code memory values resided, now becomes the string's name. In a large program with lots of text formatting, this type of structure can save quite literally hundreds of bytes of valuable code space.

Try both these small programs, and you'll see that using Cstr saves a few bytes of code: -

First the standard way of displaying text: -

Device = 24HJ128GP502
                                   ' Select the device to compile for
Declare Xtal = 16
Rsout "Hello World\r"
Rsout "How are you?\r"
Rsout "I am fine!\r"

Now using the Cstr modifier: -

Dim Text1 as Flash8 = "Hello World\r", 0
Dim Text2 as Flash8 = "How are you?\r", 0
Dim Text3 as Flash8 = "I am fine!\r", 0
Rsout Cstr Text1
Rsout Cstr Text2
Rsout Cstr Text3

Again, note the null terminators after the ASCII text in the code memory data. Without these, the microcontroller will continue to transmit data until a value of 0 is reached. The Str modifier is used for sending a string of bytes from a byte array variable. A string is a set of bytes sized values that are arranged or accessed in a certain order.

The values 1, 2, 3 would be stored in a string with the value 1 first, followed by 2 then followed by the value 3. A byte array is a similar concept to a string; it contains data that is arranged in a certain order. Each of the elements in an array is the same size. The string 1,2,3 would be stored in a byte array containing three bytes (elements).

Below is an example that displays four bytes (from a byte array): -

Dim MyArray[10] as Byte
                              ' Create a 10 element byte array.
MyArray [0] = "H"
                              ' Load the first 5 bytes of the array
MyArray [1] = "e"
                              ' With the data to send
MyArray [2] = "l"
MyArray [3] = "l"
MyArray [4] = "o"
Rsout Str MyArray\5
                              ' Display a 5-byte string.

Note that we use the optional \n argument of Str. If we didn't specify this, the microcontroller would try to keep sending characters until all 10 bytes of the array were transmitted. Since we do not wish all 10 bytes to be transmitted, we chose to tell it explicitly to only send the first 5 bytes.

The above example may also be written as: -

Dim MyArray[10] as Byte
                           ' Create a 10 element byte array.
Str MyArray = "Hello"
                           ' Load the first 5 bytes of the array
Rsout Str MyArray\5
                           ' Send 5-byte string.

The above example, has exactly the same function as the previous one. The only difference is that the string is now constructed using Str as a command instead of a modifier.

Declares

There are four Declares for use with Rsout. These are : -

Declare Rsout_Pin Port.Pin Assigns the Port and Pin that will be used to output serial data from the Rsout command. This may be any valid port on the device.

Declare Rsout_Mode Inverted, True or 1, 0 Sets the serial mode for the data transmitted by Rsout. This may be inverted or true. Alternatively, a value of 1 may be substituted to represent inverted, and 0 for true.

If the Declare is not used in the program, then the default mode is Inverted.

Declare Serial_Baud 0 to 65535 bps (Baud) Informs the Rsin and Rsout routines as to what Baud rate to receive and transmit data.

Virtually any Baud rate may be transmitted and received, but there are standard Bauds: -

300, 600, 1200, 2400, 4800, 9600, and 19200. When using a 4MHz crystal, the highest Baud rate that is reliably achievable is 9600. However, an increase in the oscillator speed allows higher Baud rates to be achieved, including 38400 Baud and above.

If the Declare is not used in the program, then the default Baud is 9600.

Declare Rsout_Pace 0 to 65535 microseconds (us) Implements a delay between characters transmitted by the Rsout command.

On occasion, the characters transmitted serially are in a stream that is too fast for the receiver to catch, this results in missed characters. To alleviate this, a delay may be implemented between each individual character transmitted by Rsout.

If the Declare is not used in the program, then the default is no delay between characters.

Notes.

Rsout is oscillator independent as long as the crystal frequency is declared at the top of the program.

See also : Declare, Rsin , Serin, Serout, Hrsin, Hrsout, Hserin, Hserout.