0% found this document useful (0 votes)
838 views35 pages

8051 Serial Communication

The document discusses serial communication using the 8051 microcontroller. It describes how the 8051 supports serial communication through its TXD and RXD pins using the RS232 standard. It explains the basics of asynchronous serial communication including start bits, stop bits, and baud rates. It provides details about the registers used for serial communication in 8051 like SBUF, SCON, and PCON. It explains the four modes of serial communication supported by 8051 and how to program the 8051 to transmit and receive data serially.

Uploaded by

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

8051 Serial Communication

The document discusses serial communication using the 8051 microcontroller. It describes how the 8051 supports serial communication through its TXD and RXD pins using the RS232 standard. It explains the basics of asynchronous serial communication including start bits, stop bits, and baud rates. It provides details about the registers used for serial communication in 8051 like SBUF, SCON, and PCON. It explains the four modes of serial communication supported by 8051 and how to program the 8051 to transmit and receive data serially.

Uploaded by

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

SERIAL

COMMUNICATION
8051
INTRODUCTION
• Serial data transmission is very commonly used for
digital data communication.
• Its main advantage is that the number of wires
needed is reduced as compared to that in parallel
communication.
• 8051 supports a full duplex serial port. Full duplex
means, it can transmit and receive a byte
simultaneously.
CONTINUED…
• 8051 has TXD and RXD pins for transmission and
reception of serial data respectively.
• The 8051 serial communication is supported by
RS232 standard. The term "RS" stands for
Recommended Standard.
• Communication between two microcontrollers and
multiprocessor communication is also possible.
Basics of Serial Communication
• Serial data communication uses two methods

– Synchronous method transfers a block of data at a time

– Asynchronous method transfers a single byte at a time

• There are special IC’s made by many manufacturers for


serial communications.

– UART (universal asynchronous Receiver transmitter)

–USART (universal synchronous-asynchronous


Receivertransmitter)
Asynchronous – Start & Stop Bit
• Asynchronous serial data communication is widely

used for character-oriented transmissions

– Each character is placed in between start and stop bits,

this is called framing.

• The start bit is always one bit, but the stop bit can be

one or two bits

• The start bit is always a 0 (low) and the stop bit(s) is 1

(high)
CONTINUED…
• In serial transmission, baud rate is one important
factor.
• The baud rate is the reciprocal of the time to send
1 bit.
• The basic mechanism of serial transmission is
that a data byte in parallel form is converted into
serial data stream. Along with some more bits like
start, stop and parity bits, a serial data frame is
sent over a line.
CONTINUED…
• There are four modes of serial data transmission
in 8051.
• In each of these modes, it is important to decide
the baud rate, the way in which serial data frame
is sent and any other information, etc.
BAUD RATE
• The 8051 transfers and receives data serially at
many different baud rates. The baud rate in the
8051 is programmable.
• For this purpose, Timer 1 is used and it must be
programmed in mode
• 2 (8 bit auto reload)
REGISTERS USED
• 8051 requires the following registers to perform
the serial communication
• SBUF (Serial Buffer)

• SCON (Serial Control Register)

• PCON (Power Control Register)


SBUF REGISTER
• It is an 8 bit register used solely for serial
communication in the 8051.
• For a byte of data to be transferred via the TXD
line, it must be placed in the SBUF register.
• Similarly, SBUF holds the byte of data when it is
received by the 8051’s RXD line.
• SBUF can be accessed like any other register in
the 8051.
CONTINUED…
• The moment a byte is written into SBUF, it is
framed with start and stop bits and transferred
serially.
• When the bits are received serially, 8051 reframes
it by eliminating the start and stop bits, making a
byte out of the data received.
• MOV SBUF,#’D’ – Load SBUF =44H (ASCII for ‘D’)

• MOV SBUF,A – Copy accumulator into SBUF


SCON REGISTER
• It is an 8 bit register that controls the serial
communication operation in the 8051.
• It is used to program the start bit, stop bit and data
bits of data framing among other things.
• It is an bit addressable register.
IMPORTANCE OF TI FLAG
• TI (Transmit Interrupt) is bit D1 of the SCON
register.
• When 8051 finishes the transfer of the 8 bit
character, it raises the TI flag to indicate that it is
ready to transfer another byte.
• This bit is raised at the beginning of the stop bit.

• After SBUF is loaded with new byte, the TI flag bit


must be forced to 0 by the “CLR TI” instruction.
IMPORTANCE OF RI FLAG
• RI (Receive Interrupt) is bit D0 of the SCON
register.
• When 8051 receives the data serially via RXD, it
gets rid of the start and stop bits and places the
byte in SBUF register. Then it raises the RI flag to
indicate that a byte has been received.
CONTINUED…
• This bit is raised at the halfway through the
stop bit.
• After SBUF contents are copied, the RI flag
bit must be forced to 0 by the “CLR RI”
instruction in order to allow the next received
byte to be placed in SBUF.
8051 SERIAL PORT – MODE 0
• The Serial Port in Mode-0 has the following
features:

1. Serial data enters and exits through RXD


2. TXD outputs the clock

3. 8 bits are transmitted / received

4. The baud rate is fixed at (1/12) of the


oscillator frequency
SERIAL COMMUNICATION MODES
8051 SERIAL PORT – MODE 1
• The Serial Port in Mode-1 has the following features:

1. Serial data enters through RXD

2. Serial data exits through TXD

3. On receive, the stop bit goes into RB8 in SCON

4. 10 bits are transmitted / received

1. Start bit (0)

2. Data bits (8)

3. Stop Bit (1)


5. Baud rate is determined by the Timer 1 over flow rate.
6. Therefore before using this mode, one has to initialize
timer 1
8051 SERIAL PORT – MODE 2
• The Serial Port in Mode-2 has the following features:

1. Serial data enters through RXD

2. Serial data exits through TXD

3. 9th data bit (TB8) can be assign value 0 or 1

4. On receive, the stop bit goes into RB8 in SCON

5. 11 bits are transmitted / received

1. Start bit (0)

2. Data bits (9)

3. Stop Bit (1)


6.Baud rate is programmable.

7. The bit SMOD in PCON and the oscillator frequency


defines the baudrate and is given by,
8051 SERIAL PORT – MODE 3
• The Serial Port in Mode-3 has the following features:

1. Serial data enters through RXD

2. Serial data exits through TXD

3. 9th data bit (TB8) can be assign value 0 or 1

4. On receive, the stop bit goes into RB8 in SCON

5. 11 bits are transmitted / received

1. Start bit (0)

2. Data bits (9)

3. Stop Bit (1)


6. Baud rate is determined by the Timer 1 over
flow rate.
PROGRAMMING 8051 TO TRANSFER
DATA SERIALLY
• In programming the 8051 to transfer character
bytes serially, the following steps must be taken

1. The TMOD register is loaded with the value 20H,


indicating the use of Timer 1 in mode 2 (8 bit auto
reload) to set the baud rate.

2. The TH1 is loaded with one of the values to set


the baud rate for serial data transfer. (Assume
XTAL= 11.0592 MHz)
CONTINUED…
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 the “CLR TI” instruction.

6. The character byte to be transferred serially


to be written into the SBUF register.
CONTINUED…
7. The TI flag bit is monitored with the use of
the instruction “JNB TI, XX” to see if the
character has been transferred completely.
8. To transfer next character, go to step 5.
PROGRAMMING 8051 TO RECEIVE
DATA SERIALLY
• In programming the 8051 to receive character
bytes serially, the following steps must be taken

1. The TMOD register is loaded with the value 20H,


indicating the use of Timer 1 in mode 2 (8 bit auto
reload) to set the baud rate.

2. The TH1 is loaded with one of the values to set


the baud rate. (Assume XTAL= 11.0592 MHz)
CONTINUED…
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 the “CLR RI” instruction.

6. The RI flag bit is monitored with the use of the


instruction “JNB RI, XX” to see if the character
has been received yet.
CONTINUED…
7. When RI is raised, SBUF has the byte. Its
contents are moved into a safe place.

8. To transfer next character, go to step 5.


• The PCON or Power Control register, as the name suggests is used to control the
8051 Microcontroller’s Power Modes and is located at 87H of the SFR Memory
Space. Using two bits in the PCON Register, the microcontroller can be set to Idle
Mode and Power Down Mode.
• During Idle Mode, the Microcontroller will stop the Clock Signal to the ALU (CPU)
but it is given to other peripherals like Timer, Serial, Interrupts, etc. In order to
terminate the Idle Mode, you have to use an Interrupt or Hardware Reset.
• In the Power Down Mode, the oscillator will be stopped and the power will be
reduced to 2V. To terminate the Power Down Mode, you have to use the Hardware
Reset.
• Apart from these two, the PCON Register can also be used for few additional
purposes. The SMOD Bit in the PCON Register is used to control the Baud Rate of
the Serial Port.
• There are two general purpose Flag Bits in the PCON Register, which can be used by
the programmer during execution.

You might also like