0% found this document useful (0 votes)
48 views

Serial Modes - Notes New

The document discusses the different serial communication modes of the 8051 microcontroller: Mode 0 uses synchronous serial communication with a fixed baud rate of oscillator/12. Mode 1 is asynchronous UART communication with a programmable baud rate. Mode 2 is multiprocessor mode that transmits an 11-bit frame with a programmable 9th bit. Mode 3 is the same as Mode 2 but with a variable baud rate. The document also provides examples of programming the 8051 for serial data transmission and reception, setting the baud rate, framing the data, monitoring flags, and moving data to and from the serial buffer register.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Serial Modes - Notes New

The document discusses the different serial communication modes of the 8051 microcontroller: Mode 0 uses synchronous serial communication with a fixed baud rate of oscillator/12. Mode 1 is asynchronous UART communication with a programmable baud rate. Mode 2 is multiprocessor mode that transmits an 11-bit frame with a programmable 9th bit. Mode 3 is the same as Mode 2 but with a variable baud rate. The document also provides examples of programming the 8051 for serial data transmission and reception, setting the baud rate, framing the data, monitoring flags, and moving data to and from the serial buffer register.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

8051 Serial Data Communication Modes of operation and programming.

Serial Data communication Modes:


Mode-0:
In this mode, the serial port works like a shift register and the data transmission works
synchronously with a clock frequency of oscillator /12. Serial data is received and transmitted
through RXD. 8 bits are transmitted/ received at a time. Pin TXD outputs the shift clock pulses
of frequency oscillator /12, which is connected to the external circuitry for synchronization. The
shift frequency or baud rate is always 1/12 of the oscillator frequency.

Mode-1 (standard UART mode):


In mode-1, the serial port functions as a standard Universal Asynchronous Receiver Transmitter
(UART) mode. 10 bits are transmitted through TXD or received through RXD. The 10 bits
consist of one start bit (which is usually '0'), 8 data bits (LSB is sent first/received first), and a
stop bit (which is usually '1'). Once received, the stop bit goes into RB8 in the special function
register SCON. The baud rate is variable. The following figure shows the way the bits are
transmitted/ received.
In receiving mode, data bits are shifted into the receiver at the programmed baud rate. The data
word (8bits) will be loaded to SBUF if the following conditions are true.

1. RI must be zero. (i.e., the previously received byte has been cleared from SBUF)

2. Mode bit SM2 = 0 or stop bit = 1. After the data is received and the data byte has been loaded
into SBUF, RI becomes one.

Mode-2 - Multiprocessor Mode :


In this mode 11 bits are transmitted through TXD or received through RXD. The various bits are
as follows: a start bit (usually '0'), 8 data bits (LSB first), a programmable 9 th (TB8 or RB8) bit
and a stop bit (usually '1'). While transmitting, the 9 th data bit (TB8 in SCON) can be assigned
the value '0' or '1'. For example, if the information of parity is to be transmitted, the parity bit (P)
in PSW could be moved into TB8. On reception of the data, the 9 th bit goes into RB8 in 'SCON',
while the stop bit is ignored. The baud rate is programmable to either 1/32 or 1/64 of the
oscillator frequency.

Mode-3:
Multi-processor mode with variable baud rate: In this mode 11 bits are transmitted through TXD
or received through RXD. The various bits are: a start bit (usually '0'), 8 data bits (LSB first), a
programmable 9th bit and a stop bit (usually '1'). Mode-3 is same as mode-2, except the fact that
the baud rate in mode-3 is variable.
Programming of serial data communication in 8051:
In programming the 8051 to transfer character bytes serially
1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit
auto-reload) to set baud rate
2. The TH1 is loaded with one of the 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 8bit 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. To transfer the next byte, go to step 5
Example: Write a program for the 8051 to transfer letter “A ”serially at 4800 baud, 8 bit
data, 1 stop bit continuously.
MOV TMOD, #20H //timer 1,mode 2(auto reload)
MOV TH1, #0FAH //4800 baud rate
MOV SCON, #50H // 8-bit, 1 stop, REN enabled
SETB TR1 // start timer 1
AGAIN: MOV SBUF, #”A” // letter “A” to transfer
HERE: JNB TI, HERE //wait for the last bit
CLR TI //clear TI for next char
SJMP AGAIN // keep sending A

In programming the 8051 to receive character bytes serially


1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit
auto-reload) to set baud rate
2. TH1 is loaded to set baud rate
3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8bit 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. To receive the next character, go to step 5
Example: Write a program for the 8051 to receive bytes of data serially, and put them in
P1, set the baud rate at 4800, 8-bit data, and 1 stop bit
MOV TMOD, #20H //timer 1, mode 2(auto reload)
MOV TH1, #0FAH //4800 baud rate
MOV SCON, #50H // 8-bit, 1 stop, REN enabled
SETB TR1 // start timer 1
HERE: JNB RI, HERE // wait for char to come in
MOV A, SBUF // saving incoming byte in A
MOV P1, A // send to port 1
CLR RI // get ready to receive next byte
SJMP HERE // keep getting data

You might also like