📄 serio.txt
字号:
8051 Serial Port Routines
by Kevin W. Clark
These files show a number of ways to use the serial port.
CHARNAME.A51 Equates for control characters
SERIO1A.A51 Auto baud rate using Timer 1, slow mode
SERIO1F.A51 Auto Baud using timer 1, fast mode
SERIO1M.A51 Manual Baud using Timer 1
SERIO110.A51 110 Baud using Timer 1
SERIO1_I.A51 Simple Interrupt driven sample.
SERIO2A.A51 Auto Baud using Timer 2
SERIO2M.A51 Manual Baud using Timer 2
SERIO_SP.A51 Split baud rate using both timer 1 and 2
SERTEST.A51 Master module for serial test program
MODE0.A51 A simple program to test MODE 0
BUILD.BAT A simple batch file to assemble and link a SERIO file
the SERIO*.A51 files contain a number of routines:
S_INIT - Initializes Serial port.
C_IN - waits for character from serial port. Returns it in A.
C_OUT - sends character in A.
C_STS - console status. if char RXD, C=1, A=char, else C=0.
STROUT - Sends in-line character string to console. String is terminated
by last character's MSB set. Hence, can only handle 7 bit ASCII.
The 8051 has 2 timers and can use only timer 1, operating as an 8 bit
auto-reload timer to generate serial baud rates. The 8052 and
supersets (80C52,'54, '58, 8051Fx,Gx ...) have three timers, and can
use timer 2 and/or timer 1 to generate serial baud rates. Timer 2 is
16 bits and operates from a higher clock rate source than timer 1.
This means that higher baud rates can be accurately generated over a
wider range of oscillator frequencies than with timer 1. Lower baud
rates can also be generated at higher oscillator frequencies.
The Auto Baud rate determining versions wait for a space character from
the terminal, measuring its length, to determine the baud rate.
The manual-baud-rate programs are all written to generate 9600 baud
from an 18.432 MHz crystal, except for the 110 baud example. Tables for
other baud rates and crystals are given in the source files.
Timer 1 baud rate generation is controlled by the reload value of the
timer, and also the value of the SMOD bit in the PCON SFR. If this bit
is set, the baud rate is doubled. This accounts for the difference
between the fast and slow mode examples.
Timer 1 can not normally be used to generate 110 baud at clock
frequencies above 10MHz, due to being only 8 bits, but low baud rates
can be generated by using it as a 16 bit timer with software reload on
interrupt. This technique is used in SERIO110.A51, and is taken from
the databook. This file also uses the serial port in mode 3 (9 bit),
instead of mode 1 (8 bit), to generate the required 2 stop bits.
No examples are given for Mode 2, or for Mode 2 or 3 in the
Multiprocessor communication mode, since these modes of operation need
multiple processors and more complex software to demonstrate. Their
operation is otherwise similar to the standard modes of operation.
SERIO1_I.A51 is a simple interrupt driven example. It has only single
character buffers for receive and transmit. A practical example of
this would have larger buffers, and its design would depend more on the
overall design of the program. For instance, the receive buffer might
buffer a reasonable number of characters before the foreground program
needed to read them, or may take care of all actions directly, and the
transmit buffer would need to be big enough to hold a complete message,
or make use of a queue of pointers to messages in XDATA or CODE space,
to avoid the necessity of copying the strings from one place to
another.
SERIO_SP.A51 is an example of split rate baud rate generation, using
both Timer 1 and Timer 2. This example sets both to 9600 Baud.
MODE0.A51 is a simple demo of the use of Mode 0, the shift register
mode. Again, real examples of this mode are dependent on the hardware
configuration. With this example, you can look at the TX and RX pins
with an oscilloscope to see the data and clock. Note that in Mode 0,
the RXD pin (P3.0), which is normally an input, becomes an input/output
for the data, while TXD (P3.1) provides the shift clock, so that in
testing it for transmit mode, it must be disconnected from the serial
line driver.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -