oUSART Object

Main Index
Object List
Back to top of pageDescription:
 Controls the PIC's USART Hardware Module.
 The following table lists the size and availability of the oUSART Object.
 ObjectSizeDescriptionA1A2B1B2C1
oUSART4 BytesControls the PIC's USART Hardware Module.xxxxx
Back to top of pageOperation:
An oUSART Object uses the PIC's Universal Universal Synchronous Asynchronous Receiver/Transmitter (USART) by setting the USART's registers in the way specified by the oUSART's properties and by responding to the interrupts generated by the USART.  I/O Line 22 is is configured to be an output which is used for transmitting serial data and I/O Line 23 is configured to be an input which is used for receiving serial data.

The USART provides a high-speed serial communication port capable of communicating at several different baud rates. It can be configured as full duplex asynchronous or synchronous and can communicate with serial devices such as CRT terminals and personal computers. It uses the standard non-return-to-zero (NRZ) format asynchronous mode (one start bit, eight data bits, and one stop bit). The USART transmits and receives the lowest significant bit first. The USART’s transmitters and receiver are functionally independent but use the same data format and baud rate.

When the USART has received new data, the oUSART Object responds by storing the new value in the Value property and setting the Received property to cvTrue.

The Value property has different functions depending on whether it is being read or written.  When read, it returns the last value received.  When a value is written to it, the value is not stored.  Instead, the value is sent serially out I/O Line 22.

The Baud property specifies at which baud rate to send and receive data.  It can specify a baud rate of 1200, 2400, 4800, 9600, 19200, 31500, 38400, or 50000 Baud.  Setting the Baud property will not only store the value written, but also cause the USART's Baud Rate Generator to be set to the value required to generate the specified Baud Rate.  When the Baud property is read, the value previously written is returned.

The serial input and output signals are TTL level signals providing 0 and 5 volts. Conversion to RS232 signals can be done with a TTL to RS232 signal converter chip such as the SN75188 or the MAX203 which will provide the voltage conversion to the RS232 levels of +12 Volts and - 12 Volts as well as providing the required signal inversion.

CAUTION: do not connect RS232 signals lines directly to the PIC's TTL level I/O.  The higher voltage of the RS232 lines will damage the TTL level circuitry.

One physical USART is implemented within the PIC.  Each dimensioned instance of the oUSART Object uses the USART and thus only one instance may be active at any given time. Setting the Operate property to 1 activates an instance of the oUSART Object and will deactivate any other oUSART Objects that were previously activated. 

Note that the PIC's USART does not provide flow control and therefore, neither does the oUSART Object.  The oSerialPort Object which uses the oUSART Object adds flow control functionality.  The oSerialL Object also has flow control but it is not based on PIC Hardware.

Back to top of pageProperties:

The following table lists the properties of the oUSART Object:

Property

Description

Value
The value of the received and transmitted data.
Object Class: oByte Value Range: 0 - 255
Data Type: Numeric Default Value: 0
If written to, the data is sent serially through the USART's transmit line located on I/O Line 22.
If read, it returns the last data received by the USART through the receive line located on I/O Line 23.
Received
A value that indicates if a byte of data has been received and placed into the Value property.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric Default Value: 0
Set when 8 bits of data have been successfully received. Must be cleared by user.
ReceivedConstantDescription
0cvFalseNo new data has been received.
1cvTrueNew data has been received.
Transmitting
A value that indicates if the serial port's transmit buffer is full.
Object Class: oLogic Value Range: 0 - 1
Data Type: Numeric (Read-Only) Default Value: 0
Set when the Value property is written to. Cleared when the 8 bits of data has begun to transmit. Any write to the Value property when Transmitting is 1, will be ignored.
TransmittingConstantDescription
0cvFalseNo data is currently being sent.
1cvTrueData is currently being sent.
Baud
A value that specifies the baud rate which controls the speed of the serial data stream.
Object Class: oProperty Value Range: 0 - 15
Data Type: Numeric Default Value: 0
When the Baud rate property is set, the Operate is checked.  If the Operate property is 1, then the Baud rate is set into the serial communications module's baud rate register.  If the Operate property is 0, then the serial communications module's baud rate register remains unchanged until the Operate property is set to 1.
BaudConstantDescription
0cvMidiSerial data communicates at 31,250 Baud. (Midi)
1cv1200Serial data communicates at 1200 Baud.
2cv2400Serial data communicates at 2400 Baud.
3cv9600Serial data communicates at 9600 Baud.
4cv4800Serial data communicates at 19,200 Baud. (Available as of firmware version B.1.0)
5cv19200Serial data communicates at 4800 Baud. (Available as of firmware version B.1.0)
6cv50000Serial data communicates at 50,000 Baud. (Available as of firmware version B.1.0)
7cv38400Serial data communicates at 38,400 Baud. (Available as of firmware version B.2.0)
Mode
A value that selects if the USART operates synchronous or asynchronous.
Object Class: oSelect0to1 Value Range: 0 - 1
Data Type: Numeric Default Value: 0
ModeDescription
0The serial port operates asynchronous
1The serial port operates synchronous, this setting is only useful if you use the PIC object to set up other registers - for Guru's only.
Operate
A value that selects whether or not the USART will receive or send data.
Object Class: oOperate Value Range: 0 - 1
Data Type: Numeric Default Value: 0
The operate property directly controls the enable bits of the USART.
OperateConstantDescription
0cvOffThe USART Hardware is not enabled.
1cvOnThe USART Hardware is enabled.
IOLineT
I/O Line 22 which is used by the USART to transmit serial data.
Object Class: oIOLine Value Range: 22
Data Type: Numeric (Read-Only) Default Value: 22
IOLineR
I/O Line 23 which is used by the USART to receive serial data.
Object Class: oIOLine Value Range: 23
Data Type: Numeric (Read-Only) Default Value: 23
Address
Returns a pointer to the address of the oCounter Object instance.
Object Class: oAddress Value Range: 0 - 127
Data Type:Pointer (Read Only) Default Value: Address of Object

Back to top of pageHardware Diagram:
The PIC's Universal Universal Synchronous Asynchronous Receiver/Transmitter (USART)
 

Back to top of pageExample:

In the following examples, the oSerial Object is used.
'This program reads an oA2D Object
'and sends the value to a PC 
'connected via a serial port.
'Note: No flow control is used.

Dim A As New oUSART
Dim B As New oA2D

Sub Main()
  B.IOLine = 1
  B.Operate = cvTrue
  A.Baud = cv9600
  A.Operate = cvTrue
  Do  
    A.Value = Str$(B)
    A.Value = 13
    A.Value = 10
  Loop
End Sub
'This program takes any serial
'data that a oUSART Object 
'has received and sends it
'back out the oUSART Object.
'Note: No flow control is used.

Dim A As New oUSART

Sub Main()
  A.Baud = cv9600
  A.Operate = cvTrue
  Do  
    If A.Received = cvTrue then
      A.Value = A.Value
    End If
  Loop
End Sub

Back to top of pageRelated Items:

 The following table lists objects that use the oUSART Object.
 ObjectDescriptionA1A2B1B2C1
oSerialHProvides a high-speed asynchronous serial I/O port using hardware specific I/O lines.xxxxx
 The following table lists objects with related functions
 ObjectDescriptionA1A2B1B2C1
oSerialPortProvides a high-speed asynchronous serial I/O port with a buffer.xxxx
oSerialLProvides a low-speed asynchronous serial Input or Output on any I/O line.xxx
Back to top of pageVersion History and Bug List:
 Firmware Ver A.1.0: Introduced.
Firmware Ver B.1.0: 19200, 4800, and 50000 baud added.
Firmware Ver B.2.0: 38400 baud added.

Bugs: No known bugs.


ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.