0% found this document useful (0 votes)
68 views28 pages

5.serial Communication - 1

Here are the key steps to receive data serially on the 8051: 1. Configure timer 1 for baud rate generation by loading TMOD and TH1 2. Configure serial port by loading SCON 3. Enable serial reception by setting RI in SCON 4. Monitor RI flag - it will be set when a character is received 5. Read received character from SBUF and save/process when RI is set 6. Clear RI to receive the next character
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views28 pages

5.serial Communication - 1

Here are the key steps to receive data serially on the 8051: 1. Configure timer 1 for baud rate generation by loading TMOD and TH1 2. Configure serial port by loading SCON 3. Enable serial reception by setting RI in SCON 4. Monitor RI flag - it will be set when a character is received 5. Read received character from SBUF and save/process when RI is set 6. Clear RI to receive the next character
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 28

serial communication

01/04/24 1
1.serial communication
Fundamentals of serial communication
Serial communication means data transfer is bit by bit.
It has 3 modes of operation
a) simplex

transmitter receiver

data transmission is only in one direction


b) half duplex

2
transmitter receiver

receiver transmitter

*data transmission is in both directions,


not at single time.
c)full duplex
transmitter receiver

receiver transmitter

3
*data transmission is in both ways. i.e. Simultaneously
serial communication to work the byte of data must be
converted to serial bits using a parallel –in –serial out shift
register ,then it can be transmitted over a single data line.

Similarly at receiving end, there must be a serial- in-


parallel_out register, to receive serial data and pack them into a
byte .

If the data has to be transferred on the telephone line ,a


MODEM must be connected to convert 0&1’s to audio tones.

When the distance is short ,the digital signal can be


transferred as it is on a simple wire and requires no modulation.
This is how a IBM PC key board transfer the data to the mother
board . 4
Serial data transfer is two ways .
1. Asynchronous data transfer – transmits byte by byte

2. Synchronous data transfer --transfers a block of data at a


time.
It is possible to write software to use either of these
methods but they are complicated.
A special IC is commonly used for this purpose.
UART (universal asynchronous receiver transmitter)
USART (universal synchronous and receiver
transmitter)
8051 has a built it in UART : Synchronous data transfer
In synchronous format, a receiver and a transmitter are
synchronized.
A block of characters are transmitted along with
synchronization information
The transmission rate is greater than 20k bits per second 5
transmitter receiver

sync sync d d

BYSYNC,HDLC,SDLC protocols will come under this class.

Asynchronous data transfer

transmitter receiver

6
start stop stop
data

mark
space

Framing =start bit +data + parity bit +1 or 2 stop bits.


Normally (when there is no data), high (logic 1)is
transferred from source to destination.

7
Rate of transmission
The rate at which the bits are transmitted in
bps.
Baud: The number of signal changes per one second.
As far as conductor wire is concerned, the baud rate and
bps are same and hence they are interchangeable
Error checks in data communication:
Parity check can only one bit of error can be detected.
Check sum is another variety to check error. Check
sum is a sum of all data byte string (without carry).

8
Data communication over telephone

Serial to Modem
Microcont parallel
roller converter
9
RS232C cable

1488 1489

2
DCE
1489 3
DTE 1488
Modem
7

10
Data Terminal Equipment : Generally computer or
microprocessor that are sending and receiving
data.
Data communication equipment modems and
other equipment that are used to send data for
long distance.
Digital data communication uses modem and &
standard phone lines.
Max 232:
It is a single chip ,which converts TTL levels
to Rs232c to voltage levels and vice versa.

11
VCC

C3
1 2
6
C1 3 C4
4
C2 GND
5
11 T1 in T1 out 14

12 R1 out R1 in 13

10 T2 in T2 out 7

9 R2 out R2 in 8

gnd
TTL side 15 RS232 side 12
8051
MAX232

P3.1 11 11
TxD 5
14 2 gnd

13 3
P3.0 10 12
RxD
DB--9

13
VCC

13 11

14 15
12 16
10
17
MAX233
2 T1 in T1 out 5

3 R1 out R1 in 4

1 T2 in T2 out 18

20 R2 out R2 in 19

gnd 14
TTL side RS233 side
SERIAL COMMUNICATION
NAME EXAMPLE A
With XTAL = 11.5092MHz, find the TH1 value needed to
have the following baud rates. (a) 9600 (b) 2400
(c)1200
Solution:
With XTAL=11.0592MHz, we have :
The machine cycle frequency of the
8051=11.0592/12=921.6KHz, and 921.6KHz/32=28,800Hz
is the frequency provided by UART to timer 1 to set baud
rate.

(a) 28,800/3 =9600 Where –3=FD (hex) is loaded


into TH1
(b) 28,800/12=2400 Where-12=F4(hex) is loaded
into TH1
(c) 28,800/24=1200 Where-24=E8(hex) is loaded
15
into TH1
Notice that dividing 1/12th of the crystal
frequency by 32 is the default value upon
activation of the 8051 RESET pin. We can
change this default setting. This is explained
at the end of this chapter.

16
11.0592MHZ MACHINE
CYCLE 28800HZ
FREQ

XTAL OSC DIVIDE BY DIVIDE BY


12 32
BY UART
921.6
KHZ

17
TIMER 1 TH1 VALUES FOR VARIOUS BAUD RATES

BUAD RATE TH1 TH1(HEX)


(DECIMAL)
9600 -3 FD

4800 -6 FA

2400 -12 F4

1200 -24 E8

18
SBUF register
It is an eight bit register used for serial communication
in 8051.

For a byte to be transformed via TXD line, it must

be placed in SBUF. Similarly, SBUF holds the byte

of data when it is received by 8051’s RXD line.

19
•The following is a program to transfer letter ‘A’ serially at 4800
baud , continuously. Observe the status of serial window, serial
port and timer port for results.

NAME EXAMPLE 16
ORG OH
MOV TMOD,#20H; Timer 1, mode 2(auto reload)
MOV TH1,# -6 H; 4800 baud rate
MOV SCON,#50H; 8 BIT,1 Stop, REN enabled
SETB TR1; Start timer 1
AGAIN: MOV SBUF, #”A”; letter A to be transferred
HERE: JNB TI,HERE ; Wait for the last bit
CLR TI; clear T1 for next char
SJMP AGAIN ; keep sending A
END
20
• The significance of TI flag: once the timer is on
TI is reset(=0). When the stop bit is transferred, 8051
rises the TI flag is set, indicating that the last character
was transmitted and ready to transfer next character. By
monitoring TI flag we make sure that we are not
overloading the SBUF register. When 8051 finishes
transferring a byte, it raises the TI flag to indicate it is
ready for the next character. After SBUF is loaded
with a new byte, TI flag is forced to zero to
transmit the new byte.

.
21
The following is a program to transfer a message ‘YES’ serially
at 9600 baud, 8-bit data,1-stop bit , continuously. Observe the
results on serial window, serial port, and timer 1.
NAME EXAMPLE 17
ORG 0H
MOV TMOD,#20H; timer 1, mode2
MOV TH1,#-3H; 9600 baud rate
MOV SCON,#50H; 8-BIT, 1-stop bit, REN
enabled
SETB TR1; start timer 1
AGAIN: MOV A, #”Y” ; Transfer ‘y’
ACALL TRANS
MOV A,#”E”
ACALL TRANS
MOV A,#”S”; TRANSFER S
22
ACALL TRANS
SJMP AGAIN ; Keep doing it
: serial letter transfer subroutine
TRANS: MOV SBUF,A; Load SBUF
HERE: JNB TI,HERE ; wait for the last bit to transfer
CLR TI ; Get ready for next byte
RET
END

23
PROGRAMMING THE 8051 TO RECEIVE DATA SERIALLY
To transfer character bytes serially, the following steps must be
followed:

the TMOD register loaded with the value 20h, indicating the timer 1 in
mode 2 to the baud rate.

The TH1 is loaded to set the baud rate for serial data transfer.
The SCON register is loaded with the value 50h,indicaitng the mode 1 ,
where an 8-bit data is started with start and stop bits.
TR1 is set to start timer1.
RI is cleared by software.
The RI bit is monitored to whether entered character is received or not.
When RI is raised, SBUF has the byte, move its contents to a safe place.
To transfer next character, go to step 5.
24
The importance of RI flag : when the stop bit is received
during receiving, 8051 makes RI=1, indicating that an
entire byte is received.

By checking RI flag, when it is raised we know that the


byte is received and is residing in SBUF register.
After content of SBUF is placed in a safe place, RI
must be forced to reset to allow the next received
character to place in SBUF register.

Assume that the 8051 serial port is connected to the


COM port of IBM PC and PC is to send and receive
data serially, P1 and P2 are connected to LED’S and
switches respectively 25
Write an 8051 program to
a) Send to PC the message “WE ARE READY”
b) Receive any data sent by PC and put it on LED’S connected
port 1
c) Get data on switches connected to P2 and send it to PC
serially
The program should perform part-a once, but parts b and c
continuously. Use the 4800 baud rate. Observe the results on
serial window, timer port, and P1 and P2.
NAME EXAMPLE 18
ORG OH
MOV P2,#OFFH;make P2 an input port
MOV TMOD, #20H; timer 1 mode 2(auto reload)
MOV TH1, #OFA; 4800 baud rate
MOV SCON, #50H; 8 bit, 1 stop, REN enabled
SETB TR1;start timer1
26
MOV DPTR,#200H; load pointer for message
H_1: CLR A
MOVC A.,@A+DPTR; get the character
JZ B_1; if last character is get out
ACALL SEND; other wise call transfer
INC DPTR
SJMP H_1 ; stay in loop
B_1: MOV A,P2 ; read data on P2
ACALL SEND; transfer it serially
ACALL RECV ; Get the serial data
MOV P1,A; display it on led’s
JMP B_1; stay in loop indefinitely
;---------------serial data transfer. ACC has the data
27
SEND: MOV SBUF, A; load the data
H_2: JNB TI,H_2; stay until here last bit
CLR TI ; get ready for next character
RET ;return to caller
;-------------------- receive data serially in simulator
RECV: JNB RI, RECV ; wait here for
MOV A, SBUF; save it in ACC
CLR RI; get ready for next character
RET ; return to caller
;-----------the message
ORG 200H
MYDATA: DB “WE ARE READY”, 0;
END
28

You might also like