8051 micro controller communicate with another peripheral device through RXD and TXD pin of port3.controller have four mode of serial communication.
1. Serial Data Mode-0 (Baud Rate Fixed) In this mode, the serial port works like a shift register and the data transmission works synchronously with a clock frequency of fosc /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 fosc /12, which is connected to the external circuitry for synchronization. The shift frequency or baud rate is always 1/12 of the oscillator frequency.
2. Serial Data Mode-1 (standard UART mode)(baud rate is variable) 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
3. Serial Data Mode-2 Multiprocessor (baud rate is fixed) 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.
f baud = (2 SMOD /64) fosc
4. Serial Data Mode-3 - Multi processor mode(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 9 th 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 (i.e., just as in mode-1).
SM0 SCON.7 Serial port mode specifier
SM1 SCON.6 Serial port mode specifier.
SM0 SM1
0 0 Serial Mode 0
0 1 Serial Mode 1, 8-bit data, 1 stop bit, 1 start bit
1 0 Serial Mode 2
1 1 Serial Mode 3
SM2 SCON.5 Used for multiprocessor communication
REN SCON.4 Set/ cleared by software to enable/ disable reception.
TB8 SCON.3 – the 9th bit that will be transmitted in mode 2/3 set/clear by software.
RB8 SCON.2– in mode 2/3 it is the 9th bit that was received .
TI SCON.1 Transmit interrupt flag. Set by hardware at the beginning of the stop Bit in mode 1.
RI SCON.0 Receive interrupt flag. Set by hardware halfway through the stop bit time in mode 1.