Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 2


The PIC18F4520 contains an enhanced USART that can detect and match a
received bit rate. The sending computer must send the value 55h (the character
“U”), which results in alternating 1s and 0s in the transmitted word. In
auto-baud-rate-detect mode, the microcontroller measures the widths of the
incoming bits and sets the serial port’s bit rate to the closest match available.
Chapter 11 has more about the PIC18F4520.


   


 


PCs can have multiple COM ports. To decide which port to use, an application
typically provides a combo box that enables the user to select a port. An applica-
tion can save the name of the last-used port and select that port as a default
when available. An application can save other parameters such as bit rate as
well. Chapter 9 has more about saving and loading port parameters.
An application can also attempt to find the correct port by sending a defined
message to each COM port. The receiving computer watches for the message
and sends a reply to let the sending computer know that the correct port has
been found. Use this method carefully, however, because unexpected data could
cause problems on other COM-port devices.


 


The data bits in a serial transmission can contain any type of information,
including commands, sensor readings, status information, error codes, configu-
ration data, or files that contain text, executable code, or other information. But
ultimately all transmitted data is bytes, or units of a different length. (In popu-
lar use, a byte is an 8-bit value. Some sources define a byte as the smallest num-
ber of bits processed by a computer as a unit and use the term octet to refer to
an 8-bit value. In this book, byte refers to an 8-bit value and unless otherwise
specified, the serial port is assumed to be configured for 8 data bits.)
Software that manages serial-port communications typically treats the data
being transmitted as either binary or text data.

6 5



With binary data, each transmitted byte is a value from 00h to FFh, and the
serial-port software assumes nothing about the meaning of the information
being transmitted. Higher-level software can interpret and use the data in any
way.
Free download pdf