Communication between PC and AT89S52 by RS232. (Range 2. exercises)

fiercebunΗλεκτρονική - Συσκευές

2 Νοε 2013 (πριν από 4 χρόνια και 11 μέρες)

88 εμφανίσεις

C
ommunication

between PC and

AT89S52

by RS232
.

(
Range

2
.
exercises
)


Assigment
:

1.

By using
AT89S52 and RS232 board, do

the communication between PC and
microcontroller. Communication will be done so that through a terminal program send
a number from 1 to 8 a
nd of the LED board will light up LEDs in sequence, which
corresponds to the number. First LED on port P2_0, second LED to P2_1, etc.


Theory
:



Block scheme of RS232 board.


RS232 board is based on manufacturer's recommendations and his function is evide
nt from
the picture on top. This board includes COM connector, for connection to serial port of PC.
TTL voltages are converted in MAX232 (IO1) to RS232 standard voltages. On board are
another two connectors for T0 and T1 signals. T0 is timer/counter 0 on
P3.4 pin, T1 is
timer/counter 1 on P3.5 pin. Connectors K1 a K2 is for expansion of function of board.


Serial channel


Serial channel in microcontroller is very important feature
because

by this channel we can
easily connect microcontroller to a PC

or to
another device
. In this days are often used circuits
as is FT232 (USB port) or MAX232 (COM port) for serial transfer channel between TTL
levels and PC.


Microcontroller from S52 family contains full
-
duplex serial channel which can
simultaneously transmit a
nd receive data. Communication is in a standard 8 or 9
-
bit
asynchronous mode or 8
-
bit synchronous mode with fixed baud rate. The communication
interface is
consisting

of 3 wires
-

RX, TX and ground (GND). Transmission part of the serial
channel is equipped

with a buffer register.


Modes of serial channel


T
h
is

registers exist
f
or us
ing

the serial channel:


SCON


Register for setting the mode and
for
control

of
serial port

SBUF


Regist
er of serial channel
(Serial Data Buffer)


is
used to receive/transmit

of
character

SMOD
bit in

PCON
register which
affecting the transmission rate



SCON


Regist
er of modes and for control

of serial
port

(Serial
CON
trol)




Regist
e
r SCON



SM2

e
nable multiprocessor communication

REN

enable/disable receiving

TB8

t
rans
mi
tted

9.dat
a

bit
in mode

2

and
3

RB8

Received

9. dat
a

bit
in mode

2

and
3


TI

Indication
if is
transceivers register
empty, in mode 0 is activated at the end of
broadcast of

8. bit
.

I
n mode
1
, 2

and

3
is activating at start of
stop
-
bit
. This bit
is set up

by HW, reset is by SW.


RI

Indication of receive
register over floating
,
in mode 0 is activated after receive
of

8. bit,
in modes
1,2 a
nd
3
is activated in the m
iddle

of stop
-
bit. This bit is
set up by HW, reset is by SW.


SCON register bits


SM1
, SM0



By combination of these bits is set the mode of serial channel. Differences
between modes are in character of broadcast
(
synchronous
,
asynchronous
),
transfer rate and
length of character.



M
ode

SM0

SM1

Typ
e of transfer

Transfer rate

0

0

0

8bit
shift

reg
ist
er

fosc/12

1

0

1

8bit
asynchronous transfer

timer
/
counter

1
or

2

2

1

0

9bit
asynchronous transfer

fosc/64
or

fosc/32

3

1

1

9bit
asynchrono
us

transfer

timer
/
counter

1
or

2


M
ode
s

of s
eri
a
l channel
.


Mode

0



use
8bit
synchronous

transfer

of
dat
a

with

definite transfer rate
.
Sometimes is this
mode name
d

as shift register
. Data
are transmitted or received at
RxD (P3.0)

pin
,
CLK signal
is transmitted at

TxD (P3.1)

pin
.

Clock frequency of transfer
is definite and is
1/12
of CLK
frequency
.
In this mode isn
’t possible full duplex transfer, because is used output TxD for
tran
s
ceiv
er

of
synchroniz
ing

signal
.






mode

0


Mode

1



use
8bit

asynchronous

data transfer
(UART)
with definite transfer rate
. Data
are
transferred

at
TxD (P3.1)

pin and are received on
RxD (P3.0)

pin
.
1
0 bit
s are received. First
bit is always zero (log.0) and is called start
-
bit
,
than is received
8 dat
a

bit
s
,
first of these 8 bits
is
l
ast significant bit
(LSB).
Last bit is called
stop
-
bit (log.1).
Transfer rate is defined by over
floatin
g of timer 1
.



mode1


Transfer rate

(
timer

1
in
m
ode

1
)




The equitation before is changed for defining the value of register TH1
:




Where
:


f0


is
CLK

frequency
(
frequency

of used crystal
oscillator
)


TH
1


content of
TH1

register of timer

1


PR


transfer rate




Mode

2



s
e
ri
al

channel use
9bit
asynchronous

transfer
of data with
user
variable transfer
rate
. Data
are transmitted at
TxD (P3.1)

pin and are received on

RxD (P3.0)

pin
.
11 bits are
transmitt
ed
. First bit is start bit

(log.0),
than are
transferred

9 dat
a

bit
s. First of
these

9 bits is
LSB bit and the last bit is the stop
-
bit (log.1).
The last 9 bit
contains

value of
TB8
. TB8 is
stored to
RB8
and
stop
-
bit
is

ignor
ed
.
Transfer rate is
1/64
of CL
K frequency of
microcontroller. By setting the
SMOD
bit in
PCON
registry is possible double
d

the transfer
rate.




Mode

2 a
nd

3



Transfer rate
:





Mode

3



use
9bit
asynchronous

data transfer with user variable transfer rate
.
In t
his mode is
the data transfer similar as in mode
2
. Different is
that

the
transfer
rate

is

defined by over
floating of timer
1

(as in mode 1)
.


Bit SMOD
in
PCON
register enable doubled transfer rate in modes

1
, 2

a
nd

3




Regist
e
r PCON


Description of a
T
erminal program:


The
TERMIN
A
L

software we can
run

by
terminal.exe

file
.
When this SW

is

running, we
must set the transfer rate
(9600 Bd

is the best
),

which we computed by the equation before
.
Than we must us
e

the CONNECT

button
.
In the command line we ca
n write numbers
between
1
and

8

and send to
microcontroller

by

-
>SEND
button

or
ENTER

button

on
keyboard
.





Terminal.exe