You are on page 1of 17

8051 SERIAL PORT

ED501

Serial Communication
RXD(P3.0) and TXD(P3.1) are the receive and transmit pins of 8051 These pins are TTL compatible MAX 232 is used as convert RS232 Voltage to TTL and vice versa

ED501

Serial Programming
Baud rate of 8051 should match with that of PC Machine cycle frequency of 8051=11.0592/12=921.6KHz And 921.6KHz/32 is the frequency provided by UART to timer1 to set baud rate 28800/3=9600, where 3 = FDH is loaded in TH1 28800/12=2400, where 12 = F4H is loaded in TH1 28800/24=1200, where 24 = E8H is loaded in TH1 When Timer1 is used to set the baud rate it must be programmed in mode2, that is 8bit auto-reload
ED501 3

SBUF
8-bit register used solely for serial communication Byte of data to be transferred via TXD or received through RXD When byte is written to SBUF it is framed with start and stop bits and transferred serially via TXD pin When the bits are received serially via RXD, the 8051 deframes it by eliminating start and stop bits, making a byte out of data received, then placing it in SBUF

ED501

SCON
8-bit serial control register

ED501

SCON Bits
SM2: multi processor communication bit REN: Receive enable bit TB8: Transmitted bit 8 (Normally we have 0-7 bits transmitted/received) RB8: Received bit 8 TI: Transmit interrupt flag RI: Receive interrupt flag
ED501 6

Serial Modes

ED501

Modes
Mode0
8 data bits, baud rate is 1/12 of osc.freq

Mode1
10 bits: start bit(0), 8 data bits, stop bit(1)

Mode2
11bits: start bit(0), 8 data bits,programmable 9th bit, stop bit(0) Baud rate is 1/64 or 1/32 of osc.freq

Mode3
11bits: start bit(0), 8 data bits,programmable 9th bit, stop bit(0) Baud rate is variable ED501

Mode-1 (standard UART mode)


serial port functions as a standard Universal Asynchronous Receiver Transmitter (UART) mode. 10 bits are transmitted through TXD or received through RXD

ED501

Mode-1 (standard UART mode)


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.
ED501 10

Baud Rate
Mode1 has variable baud rate, which can be generated by Timer1 or 2 Timer1 is used in 8-bit auto reload mode
Baud rate =
K *Oscillator Frequency/32*12*[256-(TH1)] K=1, if SMOD=0,, K=2, if SMOD=1 Thus, TH1= 256- [(K*OSC Freq)/(384*baud)]

ED501

11

Data Transmission
Transmission of serial data begins at any time when data is written to SBUF. Pin P3.1 (Alternate function bit TXD) is used to transmit data to the serial data network. TI is set to 1 when data has been transmitted. This signifies that SBUF is empty so that another byte can be sent.
ED501 12

Steps to transfer serially


1. 2. 3. 4. 5. 6. 7. 8. TMOD=20H, for timer1 in mode2 TH1 loaded with value for any one baud SCON=50H, Mode1,8-bit data+start+stop TR1 is set to 1 to start timer1 TI is cleared by CLR TI Data is written to SBUF Check for TI flag or Serial Interrupt Transmit next byte, go to 5
ED501 13

Data Reception
Reception of serial data begins if the receive enable bit is set to 1 for all modes. Pin P3.0 (Alternate function bit RXD) is used to receive data from the serial data network. Receive interrupt flag, RI, is set after the data has been received in all modes. The data gets stored in SBUF register from where it can be read.
ED501 14

Steps to receive serially


1. 2. 3. 4. 5. 6. 7. 8. TMOD=20H, for timer1 in mode2 TH1 loaded with value for any one baud SCON=50H, Mode1,8-bit data+start+stop TR1 is set to 1 to start timer1 RI is cleared by CLR RI Check for RI flag or Serial Interrupt On Interrupt or RI set, SBUF has the byte To receive next character go to 5
ED501 15

To double baud rate


Use higher frequency crystal To change a bit in PCON(power control) register SMOD bit of PCON is 0 on 8051 reset, it can be set in software to double the baud rate MOV A,PCON SETB ACC.7 MOV PCON,A

ED501

16

I request Electronics and communication ENGINEERING students to visit my blog for more abhishek1ek.blogspot.com awhengineering.blogspot.com

ED501

17

You might also like