Professional Documents
Culture Documents
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
ED501
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
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
ED501
16
I request Electronics and communication ENGINEERING students to visit my blog for more abhishek1ek.blogspot.com awhengineering.blogspot.com
ED501
17