Positron Compiler Documentation

HSerout, HSerout2, HSerout3, HSerout4, HSerout5

Positron8 · Revision 4.0.6.5 · PDF pages 226–229

HSerout [Item {, Item... }] HSerout2 [Item {, Item... }] HSerout3 [Item {, Item... }] HSerout4 [Item {, Item... }] Hserout5 [Item {, Item... }]

Transmit one or more Items from the hardware serial port on devices that contains one or more USART peripherals. If HSerout2, HSerout3, Hserout4, or Hserout5 are used, the device must contain that amount of USARTs.

Item may be a constant, variable, expression, string list, or inline command. There are no operators 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

At ypos,xpos Position the cursor on a serial LCD

ClsClear a serial LCD (also creates a 30ms delay)
Bin{1..32}Send binary digits
Dec{0..10}Send decimal digits (amount of digits after decimal point with floating point)
Hex{1..8}Send hexadecimal digits
Sbin{1..32}Send signed binary digits
Sdec{0..10}Send signed decimal digits
Shex{1..8}Send signed hexadecimal digits
Ibin{1..32}Send binary digits with a preceding '%' identifier
Idec{0..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{0..10}Send signed decimal digits with a preceding '#' identifier
IShex{1..8}Send signed hexadecimal digits with a preceding '$' identifier
Rep c\nSend character c repeated n times
Str array\nSend all or part of an array
Cstr cdataSend string data defined in a Cdata statement.

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
HSerout [Dec2 MyFloat]   ' Send 2 values after the decimal point

The above program snippet will transmit the ASCII representation of 3.14

View original PDF page 226Open page in PDFOriginal PDF page 226

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
HSerout [Dec MyFloat]   ' Send 3 values after the decimal point

The above program snippet will transmit the ASCII representation of 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
HSerout [Dec MyFloat]   ' Send 3 values after the decimal point

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

Hex or Bin modifiers cannot be used with floating point values or variables.

The Xpos and Ypos values in the At modifier both start at 1. For example, to place the text "Hello World" on line 1, position 1, the code would be: -

HSerout [At 1, 1, "Hello World"]
  Device = 16F1829
  Declare Xtal = 20  ' Tell the compiler the device will be operating at 20MHz
  Declare Hserial_Baud = 9600      ' Set Baud rate to 9600 for HSerout

  Dim MyByte as Byte = 123
  Dim MyWord as Word = 1234
  Dim MyDword as Dword = 12345

   HSerout ["Hello World"]          ' Display the text "Hello World"
   HSerout ["MyByte= ", Dec MyByte] ' Display the decimal value held in MyByte
   HSerout ["MyByte= ", Hex MyByte] ' Display the hexadecimal value held in MyByte
   HSerout ["MyByte= ", Bin MyByte] ' Display the binary value held in MyByte
'
' Display 6 hex characters of a Dword type variable
'
  HSerout ["MyDwordd= ", Hex6 MyDword]
' Display a negative value on a serial LCD or terminal.
  Symbol cNegative = -200
  HSerout [At 1, 1, SDec cNegative]
' Display a negative value on a serial LCD or terminal, with a preceding identifier.
  HSerout [At 1, 1, ISHex -$1234]

Example 3 will transmit the text $-1234.

Some PICmicros™ have the ability to read and write to their own flash memory. And although writing to this memory too many times is unhealthy for the PICmicro™, reading this memory is both fast, and harmless.

View original PDF page 227Open page in PDFOriginal PDF page 227

Which offers a unique form of data storage and retrieval, the Cdata command proves this, as it uses the mechanism of reading and storing in the PICmicro's™ flash memory.

Combining the unique features of the ‘self modifying PICmicro's™' with a string format, the compiler is capable of reducing the overhead of printing, or transmitting large amounts of text data. The Cstr modifier may be used in commands that deal with text processing i.e. Serout, HRsout, and Print etc.

The Cstr modifier is used in conjunction with the Cdata directive or the Dim as Flashx directive. The Cdata directive is used for initially creating the string of characters: -

String1: Cdata "Hello World", 0

Or with Dim As Flash8:

Dim String1 as Flash8 = "Hello World", 0

The above lines of code 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:

HSerout [Cstr String1]

The label that declared the address where the list of flash memory values reside, now becomes the string's name.

View original PDF page 228Open page in PDFOriginal PDF page 228

The term 'virtual string' relates to the fact that a string formed from the Cdata command cannot be written too, but only read from.

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 bMyArray[10] as Byte = "HELLO"  ' Create a 10 element array, and pre-load it
HSerout [Str bMyArray\5]           ' Display a 5-byte string

Note that we use the optional \n argument of Str. If we didn't specify this, the PICmicro™ 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.

Declares

There are several Declare directives for use with HSerout, HSerout2, HSerout3, Hserout4, and Hserout5. These are: -

Declare HSerout_Pin, HSerout2_Pin, HSerout3_Pin, Hserout4_Pin, or Hserout5_Pin = Port.Pin For devices that have PPS (Peripheral Pin Select), the port and pin used for the TX lines must be given, so that the compiler can setup the PPS SFRs before the program starts. This may be any valid port on the microcontroller, but check the datasheet to see if the Port is valid for the peripheral.

Declare Hserial_Baud, Hserial2_Baud, Hserial3_Baud, Hserial4_Baud, or Hserial5_Baud = Constant value Sets the Baud rate that will be used to transmit or receive a value serially. The Baud rate is calculated using the Xtal frequency declared in the program, and the compiler automatically sets up the required SFRs to work as close to that Baud required as possible.

Declare Hserial_Parity, Hserial2_Parity, Hserial3_Parity, Hserial4_Parity, or Hserial5_Parity = Odd or Even Enables/Disables parity on the serial port. For both HSerout and HSerin The default serial data format is 8N1, 8 data bits, no parity bit and 1 stop bit. 7E1 (7 data bits, even parity, 1 stop bit) or 7O1 (7data bits, odd parity, 1 stop bit) may be enabled using the Hserial_Parity declare.

Declare Hserial_Parity = Even    ' Use if even parity desired
Declare Hserial_Parity = Odd    ' Use if odd parity desired

HSerout can only be used with devices that contain a hardware USART. See the specific device's data sheet for further information concerning the serial input pin as well as other relevant parameters. Since the serial transmission is done in hardware, it is not possible to set the levels to an inverted state in order to eliminate an RS232 driver. Therefore a suitable driver should be used with HSerout . See HRsin for circuit examples

See also : Declare, Rsin, Rsout, Serin, Serout, HSerin, HSerin2, HSerin3, HSerin4.

View original PDF page 229Open page in PDFOriginal PDF page 229