0% found this document useful (0 votes)
43 views8 pages

MAA Notes - Serial

Uploaded by

Majhe Guruji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views8 pages

MAA Notes - Serial

Uploaded by

Majhe Guruji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Serial Communication

UART (Universal Asynchronous Receiver/Transmitter) is a fundamental


protocol used for serial data exchange between devices.
8051 has built-in UART with RXD (serial data receive pin) and TXD (serial
data transmit pin) on PORT3.0 and PORT3.1 respectively.

Asynchronous communication
Asynchronous serial communication is widely used for byte-oriented transmission.

Frame structure in Asynchronous communication:


START bit: It is a bit with which serial communication starts and it is
always low.
Data bits packet: Data bits can be 5 to 9 bits packet. Normally we use 8 data
bit packet, which is always sent after the START bit.
STOP bit: This is one or two bits. It is sent after the data bits packet to
indicate the end of the frame. The stop bit is always logic high.
In an asynchronous serial communication frame, the first START bit
followed by the data byte and at last STOP bit forms a 10-bit frame. Sometimes the
last bit is also used as a parity bit.
Data transmission rate - Baud rate
The data transmission rate is measured in bits per second (bps). In the binary
system, it is also called a baud rate (number of signal changes per second).
Standard baud rates supported are 1200, 2400, 4800, 19200, 38400, 57600, and
115200. Normally most of the time 9600 bps is used when speed is not a big issue.

Baud Rate calculation:


To meet the standard baud rates generally crystal with 11.0592 MHz is used.
As we know, 8051 divides crystal frequency by 12 to get a machine cycle
frequency of 921.6 kHz.
The internal UART block of 8051 divides this machine cycle frequency by 32,
which gives the frequency of 28800 Hz which is used by UART.
To achieve a baud rate of 9600, the 28800 Hz frequency should be divided by 3.
To achieve a baud rate of 4800, the 28800 Hz frequency should be divided by 6.
To achieve a baud rate of 2400, the 28800 Hz frequency should be divided by 12.
To achieve a baud rate of 1200, the 28800 Hz frequency should be divided by 24.
SBUF Register:

It is an 8-bit register and is used for serial communication of data in 8051


microcontroller. Whatever data is required to be transmitted via TXD line must be placed in the
SBUF register. Similarly the received data via RXD line is saved in SBUF register. When data is
written to SBUF register then it is framed in b/w start and stop bit before it is transmitted via
TXD line and similarly during reception of data start and stop bits are removed and actual data
bits are extracted from the received frame and then it is placed in the SBUF register.
Steps to send data serially:
1. Set baud rate by loading TMOD register with the value 20H, this indicating
timer 1 in mode2 (8-bit auto-reload) to set baud rate
2. The TH1 is loaded with proper values to set baud rate for serial data transfer
3. The SCON register is loaded with the value 50H, indicating serial mode 1,
where an 8- bit data is framed with start and stop bits
4. TR1 is set to 1 to start timer 1
5. TI is cleared by CLR TI instruction
6. The character byte to be transferred serially is written into SBUF register
7. The TI flag bit is monitored with the use of instruction JNB TI,xx to see if the
character has been transferred completely
8. TI flag must be cleared by software
9. To transfer the next byte, go to step 5

Steps to receive data serially:


1. Set baud rate by loading TMOD register with the value 20H, this indicating
timer 1 in mode 2 (8-bit auto-reload) to set baud rate
2. The TH1 is loaded with proper values to set baud rate
3. The SCON register is loaded with the value 50H, indicating serial mode 1,
where an 8- bit data is framed with start and stop bits
4. TR1 is set to 1 to start timer 1
5. RI is cleared by CLR RI instruction
6. The RI flag bit is monitored with the use of instruction JNB RI,xx to see if an
entire character has been received yet
7. When RI is raised, SBUF has the byte; its contents are moved into a safe place
8. RI flag must be cleared by software
9. To receive next character, go to step 5
Importance of the TI flag:
Check the TI flag bit, we know whether or not 8051 is ready to transfer
another byte. TI flag bit is raised by the 8051 after transfer of data. TI flag is
cleared by the programmer by instruction like “CLR TI”. When writing a byte into
SBUF, before the TI flag bit is raised, it may lead to loss of a portion of the byte
being transferred.

Importance of the RI flag bit:


It receives the start bit, next bit is the first bit of the character about to be
received. When the last bit is received, a byte is formed and placed in SBUF. when
stop bit is received, it makes RI = 1 indicating entire character byte has been
received and can be read before overwritten by next data. When RI=1, received
byte is in the SBUF register, copy SBUF contents to a safe place. After the SBUF
contents are copied the RI flag bit must be cleared to 0.

Increasing the baud rate:


Baud rate can be increase by two ways-

1. Increasing frequency of crystal


2. Change bit in PCON register

PCON
It is 8-bit register. When 8051 is powered up, SMOD is zero. By setting the
SMOD, baud rate can be doubled. If SMOD = 0 (which is its value on reset), the
baud rate is 1/64 the oscillator frequency. If SMOD = 1, the baud rate is 1/32 the
oscillator frequency.
Program to transfer letter “D” serially at 9800baud, continuously:
MOV TMOD,#20H ; timer 1,mode 2(auto reload)
MOV TH1, #0FDH ; 9600 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; start timer 1
AGAIN: MOV SBUF, #”D” ; letter “D” to transfer
HERE: JNB TI, HERE ; wait for the last bit
CLR TI ;clear TI for next char
SJMP AGAIN ; keep sending A

Program to receive bytes of data serially, and put them in P2, set the baud
rate at 9600, 8-bit data, and 1 stop bit:

MOV TMOD, #20H ; timer 1,mode 2(auto reload)


MOV TH1, #-3 ; 9600 baud rate
MOV SCON, #50H ; 8-bit, 1 stop, REN enabled
SETB TR1 ; start timer 1 ; wait for char to come in
HERE: JNB RI, HERE ; saving incoming byte in A
MOV A, SBUF ; send to port 1
MOV P2, A ; get ready to receive next byte
CLR RI ; keep getting data
SJMP HERE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy