Lab Serial Communication 8051
Lab Serial Communication 8051
Bit# 7 6 5 4 3 2 1 0
Description Serial port mode bit 0 Serial port mode bit 1 Mutliprocessor Communications Enable (explained later) Receiver Enable. This bit must be set in order to receive characters Transmit bit 8. The 9th bit to transmit in mode 2 and 3 Receive bit 8. The 9th bit received in mode 2 and 3 Transmit Flag. Set when a byte has been completely transmitted Receive Flag. Set when a byte has been completely received
SM0
SM1
Mode
Explanation
Baud Rate
Page |1
0 0 1 1
0 1 0 1
0 1 2 3
Following table shows some standard baud rates used for serial communication. Right most column shows the value of higher byte of timer 1, to generate the respective baud rate. Baud Rate 9600 4800 2400 1200 Crystal Freq 11.0592 MHz 11.0592 MHz 11.0592 MHz 11.0592 MHz TH1 decimal -3 -6 -12 -24 TH1 Hex FD FA F4 E8
To calculate the value of TH1 for a required baud rate, following formula can also be used:
Steps to receive a character throughUART of 8051: 1. Configure SCON SFR to Mode 1 and enable the reception through REN bit. 2. Configure Timer 1 to 8 bit auto-reload mode by assigning appropriate value to TMOD SFR 3. Load TH1 and TL1 with a value given in theTH1 Hex column of above table for a required baud rate generation. 4. Set ES and EA bits in IE SFR to enable serial port and global interrupts 5. Start the Timer 1 by setting TR1 bit of TCON register. 6. Reset the RI bit of SCON SFR 7. Check for RI flag. 8. When RI goes up, copy the received byte from SBUF register and move it to a safe location. 9. Now reset the RI flag to enable reception of another byte.
Steps to transmit a character from UART of 8051: 1. There is no need to configure the serial port again from step 1 to 5. These steps are required to be configured only one time. 2. Reset TI flag of SCON SFR 3. Put the character in SBUF for start of transmission. When a character is copied into SBUF, transmission is started immediately. 4. Wait until TI flag is raised, which indicates that complete byte has been transmitted. 5. Now reset the TI flag and repeat the step 3 to transmit another byte.
Page |2
U1 X1
19 XTAL1 11.0592MHz 18 XTAL2 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD 39 38 37 36 35 34 33 32 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 RED
C5
10uF 1 3 C1T1OUT R1IN T2OUT R2IN VS+ VSC2+ 4 C2MAX232 5 14 13 7 8 2 6
C2
33pF
U2
C6
10uF
C7
10uF
R3
10k
RST
U3
20 19 18 17 16 15 14 13 12 11 11 12 10 9
C3
10uF VCC 29 30 31 PSEN ALE EA
AT89C51
MAX232
U4
20 19 18 17 16 15 14 13 12 11 RED 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 AT89C51
J1
1 6 2 7 3 8 4 9 5 CONN-D9F
C4
10uF RXD TXD RTS CTS
// // // // //
// 8 Bit auto-reload mode on Timer 1 // Initialize TH1 for 9600 Baud rate // Initialize TL1 for 9600 Baud rate // Mode 1, 8-bit, through Timer 1, Enable Reception // Enable serial Interrupt // Enable Global Interrupt Start Time 1 Clear Transmit Flag Clear Receive Flag Initialized port 1 with zero Initialized port 2 with zero // Forever loop
Page |3