LAB 11 8051 Serial Programming
LAB 11 8051 Serial Programming
8051 SERIAL
PROGRAMMING
INTRODUCTION
• Synchronous
• Asynchronous
SYNCHRONOUS COMMUNICATION
In synchronous communications, the two devices
initially synchronize themselves to each other, and then
continually send characters to stay in sync.
ASYNCHRONOUS COMMUNICATION
Asynchronous means "no synchronization". The
beginning and end of each byte of data is identified by
start and stop bits. The start bit indicates when the data
byte is about to begin and the stop bit signals when it
ends.
ASYNCHRONOUS COMMUNICATION
START AND STOP BIT
The data is transmitted in serial format with LSB of the byte to be
transmitted (shifted out) first among the data bits.
The general format for serial transmission is:
Stop bit
4 REN 9Ch Receiver Enable. This bit must be set in order to receive
characters.
3 TB8 9Bh Transmit bit 8. The 9th bit to transmit in mode 2 and 3.
2 RB8 9Ah Receive bit 8. The 9th bit received in mode 2 and 3.
(*) Note: The baud rate indicated in this table is doubled if PCON.7 (SMOD) is set.
Steps To Configure Serial Port for communication
1. Calculate the number for timer overflow to achieve correct baud
rate.
2. Configure Timer
a. Configure Timer 1 to mode 2 (8-bit auto-reload) (TCON).
b. Set TH1 to calculated value to reflect the correct frequency for baud rate
(from step 1).
c. Run timer (TR1).
3. Configure Serial Port to required mode and set the require bit to
activate the receive enable (SCON).
4. Set PCON.7 (SMOD) to double the baud rate (if required).
5. Start receiving or transmitting the data.
CALCULATE NUMBER FOR TIMER OVERFLOW
Baud Rate= Timer1 overflow / 32
Timer1 overflow = Baud rate x 32 ( if SMOD=1 then x by 16)
Timer1 overflow = Baud rate x 32
TH1 = (crystal freq (hz)/12) / (Baud rate * 32)