Author :
Craig
Steiner
Source :
8052.com
Book :
The
8051/8052
Microcontroller:
Architecture,
Assembly
Language,
And
Hardware
Interfacing
(Paperback)
Setting
the
Serial
Port
Mode
The
first
thing we
must do
when
using
the
8051’s
integrated
serial
port is,
obviously,
configure
it. This
lets us
tell the
8051 how
many
data
bits we
want,
the baud
rate we
will be
using,
and how
the baud
rate
will be
determined.
First,
let’s
present
the
"Serial
Control"
(SCON)
SFR and
define
what
each bit
of the
SFR
represents:
Bit |
Name |
Bit Address |
Explanation of Function |
7 |
SM0 |
9Fh |
Serial port mode bit 0 |
6 |
SM1 |
9Eh |
Serial port mode bit 1. |
5 |
SM2 |
9Dh |
Multiprocessor Communications Enable (explained later) |
4 |
REN |
9Ch |
Receiver Enable. This bit must be set in order to receive characters. |
3 |
TB8 |
9Bh |
Transmit bit 8. The 9th bit to transmit in mode 2 and 3. |
2 |
RB8 |
9Ah |
Receive bit 8. The 9th bit received in mode 2 and 3. |
1 |
TI |
99h |
Transmit Flag. Set when a byte has been completely transmitted. |
0 |
RI |
98h |
Receive Flag. Set when a byte has been completely received. |
Additionally,
it is
necessary
to
define
the
function
of SM0
and SM1
by an
additional
table:
SM0 |
SM1 |
Serial Mode |
Explanation |
Baud Rate |
0 |
0 |
0 |
8-bit Shift Register |
Oscillator / 12 |
0 |
1 |
1 |
8-bit UART |
Set by Timer 1 (*) |
1 |
0 |
2 |
9-bit UART |
Oscillator / 32 (*) |
1 |
1 |
3 |
9-bit UART |
Set by Timer 1 (*) |
(*)
Note:
The baud
rate
indicated
in this
table is
doubled
if
PCON.7 (SMOD)
is set.
The SCON
SFR
allows
us to
configure
the
Serial
Port.
Thus,
we’ll go
through
each bit
and
review
it’s
function.
The
first
four
bits
(bits 4
through
7) are
configuration
bits.
>>>
Enter
here for
detail
on
"Setting
the
Serial
Port
Mode"
<<<