Hrsout, Hrsout2, Hrsout3, Hrsout4
Syntax
Hrsout Item {, Item... }
Overview
Transmit one or more Items from a USART on devices that support asynchronous serial communications in hardware.
Parameters
Item may be a constant, variable, expression, string list, or inline command. 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
Hrsout Dec2 MyFloat ' Send 2 digits after the decimal point
The above program will transmit the ASCII characters “3.14”
If the digit after the Dec modifier is omitted, then 3 digits will be displayed after the decimal point.
Dim MyFloat as Float
MyFloat = 3.1456
Hrsout Dec MyFloat ' Send 3 digits after the decimal point
The above program will transmit the ASCII characters “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
Hrsout Dec MyFloat ' Send 3 digits after the decimal point
The above program will transmit the ASCII characters “-3.145”
Example 1
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 32
Declare Hserial_Baud = 9600 ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Dim MyByte as Byte
Dim MyWord as Word
Dim MyDword as Dword
CLKDIV = 0 ' CPU peripheral clock ratio set to 1:1
Write_OSCCONH(%00010000) ' Enable PLL
RPOR7 = 3 ' Make RP14(PORTB.14) the pin for UART1 TX
Hrsout "Hello World\r" ' Display the text "Hello World"
Hrsout "Var1= ", Dec MyByte, 13 ' Display the decimal value of MyByte
Hrsout "Var1= ", Hex MyByte, 13 ' Display the hexadecimal value of MyByte
Hrsout "Var1= ", Bin MyByte, 13 ' Display the binary value of MyByte
Hrsout "MyDword= ", Hex6 MyDword, 13 ' Display 6 hex characters
' For internal oscillator with PLL
'
Config Config1 = JTAGEN_OFF, GCP_OFF, GWRP_OFF, BKBUG_OFF, COE_OFF,_
ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRCPLL,_
FCKSM_CSDCMD, OSCIOFNC_ON, POSCMOD_NONE
The Cstr modifier may be used in commands that deal with text processing i.e. Serout, Hserout, and Print etc. However, the Cstr keyword is not always required, because the compiler recognises a label name as a null terminated string of characters.
The Cstr modifier can be used in conjunction with code memory strings. The Dim as Code directive is used for initially creating the string of characters: -
Dim MyCodeString as Code = "Hello World", 0
The above line of case will create, in code memory, the values that make up the ASCII text "Hello World", at address MyCodeString. 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:
Hrsout MyCodeString
The label that declared the address where the list of flash memory values resided, now becomes the flash memory string's name. For example, to transmit using a flash memory string: -
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 32
Declare Hserial_Baud = 9600 ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
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
CLKDIV = 0 ' CPU peripheral clock ratio set to 1:1
Write_OSCCONH(%00010000) ' Enable PLL
RPOR7 = 3 ' Make PPS Pin RP14 U1TX
Hrsout Text1
Hrsout Text2
Hrsout Text3
'
' For internal oscillator with PLL
'
Config Config1 = JTAGEN_OFF, GCP_OFF, GWRP_OFF, BKBUG_OFF, COE_OFF,_
ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRCPLL,_
FCKSM_CSDCMD, OSCIOFNC_ON, POSCMOD_NONE
Note the null terminators after the ASCII text in the flash memory strings. Without these, the device will continue to transmit data until it sees a value of 0.
Internally, the compiler is placing the quoted strings of characters into code memory, therefore either of the above constructs is valid, however, the compiler also internally combines quoted strings that are identical, meaning that the first of the above constructs can be more efficient in some cases.
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"
Hrsout 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
Hrsout 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 several Declare directives for use with the Hrsout commands. These are: -
For HRSout
Declare HRsout_Pin Port.Pin Declares the port and pin used for USART1 transmission (TX). The location of the port and pin is dictated by the device's PPS (Peripheral Pin Select) options. Note that this declare will not alter any PPS (Peripheral Pin Select) SFRs.
There is no default setting for this Declare and it must be used within the BASIC program.
Declare Hserial_Baud Constant value Sets the BAUD rate that will be used to transmit a value serially. The Baud rate is calculated using the Xtal frequency declared in the program. The default Baud rate if the Declare is not included in the program listing is 2400 Baud.
Declare Hserial_Parity Odd or Even Enables/Disables parity on the serial port. For both Hrsout and Hrsin 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
Declare Hrsout_Pace 0 to 65535 microseconds (us) Implements a delay between characters transmitted by the Hrsout 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 Hrsout.
If the Declare is not used in the program, then the default is no delay between characters.
For HRsout2
Declare HRsout2_Pin Port.Pin Declares the port and pin used for USART2 transmission (TX). The location of the port and pin is dictated by the device's PPS (Peripheral Pin Select) options. Note that this declare will not alter any PPS (Peripheral Pin Select) SFRs.
There is no default setting for this Declare and it must be used within the BASIC program.
Declare Hserial2_Baud Constant value Sets the BAUD rate that will be used to transmit a value serially. The Baud rate is calculated using the Xtal frequency declared in the program.
Declare Hserial2_Parity Odd or Even Enables/Disables parity on the serial port. For both Hrsout2 and Hrsin2 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 Hserial2_Parity declare.
Declare Hserial2_Parity = Even ' Use if even parity desired
Declare Hserial2_Parity = Odd ' Use if odd parity desired
Declare Hrsout2_Pace 0 to 65535 microseconds (us) Implements a delay between characters transmitted by the Hrsout2 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 Hrsout2.
If the Declare is not used in the program, then the default is no delay between characters.
For HRsout3
Declare HRsout3_Pin Port.Pin Declares the port and pin used for USART3 transmission (TX). The location of the port and pin is dictated by the device's PPS (Peripheral Pin Select) options. Note that this declare will not alter any PPS (Peripheral Pin Select) SFRs.
There is no default setting for this Declare and it must be used within the BASIC program.
Declare Hserial3_Baud Constant value Sets the BAUD rate that will be used to transmit a value serially. The Baud rate is calculated using the Xtal frequency declared in the program.
Declare Hserial3_Parity Odd or Even Enables/Disables parity on the serial port. For both Hrsout3 and Hrsin3 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 Hserial3_Parity declare.
Declare Hserial3_Parity = Even ' Use if even parity desired
Declare Hserial3_Parity = Odd ' Use if odd parity desired
Declare Hrsout3_Pace 0 to 65535 microseconds (us) Implements a delay between characters transmitted by the HRsout3 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 Hrsout3.
If the Declare is not used in the program, then the default is no delay between characters.
For HRsout4
Declare HRsout4_Pin Port.Pin Declares the port and pin used for USART4 transmission (TX). The location of the port and pin is dictated by the device's PPS (Peripheral Pin Select) options. Note that this declare will not alter any PPS (Peripheral Pin Select) SFRs.
There is no default setting for this Declare and it must be used within the BASIC program.
Declare Hserial4_Baud Constant value Sets the BAUD rate that will be used to transmit a value serially. The Baud rate is calculated using the Xtal frequency declared in the program.
Declare Hserial4_Parity Odd or Even Enables/Disables parity on the serial port. For both Hrsout4 and Hrsin4 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 Hserial4_Parity declare.
Declare Hserial4_Parity = Even ' Use if even parity desired
Declare Hserial4_Parity = Odd ' Use if odd parity desired
Declare Hrsout4_Pace 0 to 65535 microseconds (us) Implements a delay between characters transmitted by the Hrsout4 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 Hrsout4.
If the Declare is not used in the program, then the default is no delay between characters.
Notes.
The Hrsout commands 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.
See also : Declare, Rsin, Rsout, Serin, Serout, Hrsin, Hserin, Hserout.





