SlideShare a Scribd company logo
1 of 30
Seminar 
on 
SERIAL COMMUNICATION 
session 1 
Presented by— 
somu chaitanya 
12MT06PED019
Basics of communication 
PARALLEL 
often 8 or more lines (wire conductors) are used to 
transfer data to a device that is only a few feet away 
SERIAL 
to transfer to a device located many meters away, the 
serial method is used 
 The data is sent one bit at a time
Parallel: expensive-short distance-fast – no 
modulation 
Serial: cheaper- long(two diff cities by modem) – 
slow
Why serial???? 
To reduce the cost of cabling 
Minimise the effect of noise 
Availability of suitable communication media 
Inherent device characteristics 
Small connector 
Distributed computing 
Sensor networking
Types of serial data transfer
Basics of serial 
At the transmitting end, the byte of data must be 
converted to serial bits using parallel-in-serial-out 
shift register 
At the receiving end, there is a serial-in-parallel-out 
shift register to receive the serial data 
When the distance is short, the digital signal can be 
transferred as it is on a simple wire and requires no 
modulation 
If data is to be transferred on the telephone line, it 
must be converted from 0s and 1s to audio tones. 
This conversion is performed by a device called 
“modem”
Serial data communication uses 
two methods: 
Synchronous – transfers a block at a time 
Asynchronous – transfers a single byte at a 
time 
IC chips used to write a program are 
UART (universal asynchronous Receiver transmitter) 
USART (universal synchronous-asynchronous 
Receiver-transmitter)
ASYNCHRONOUS MODE 
start and stop bit 
In asynchronous transmission 
When there is no transfer the signal is 
high 
Transmission begins with a start (low) bit 
LSB first 
Finally 1 stop bit (high) 
Data transfer rate (baud rate) is stated in 
bps
Advantage: 
Frequency tolerant. 
Disadvantage 
overhead
SYNCHRONOUS MODE: 
Advantage: 
Overhead is small. 
Disadvantage: 
• Clock frequency should be identical.
DATA TRANSFER RATE 
How fast data is transferred? 
Three methods to describe the speed. 
Data Rate(bps) 
Number of bits transferred per second. 
Baud rate(Hz) 
Number of signal changes per second. 
Effective Data Rate 
Number of actual data bits transferred per second
Data Transfer Rate 
 IBM PC/XT could transfer data at the rate 
of 100 to 9600 bps 
Pentium-based PCs transfer data at rates as 
high as 56K bps 
In asynchronous serial data communication, 
the baud rate is limited to 100K bps
Key features of 8051 serial 
interface 
Full-duplex communication 
Serial circuit is provided with two buffers– 
1. For communication b/w the microprocessor 
2. For serially taking data from serial line 
SFR (also called as SBUF ) whose mnemonics is same 
for both receiving and transmitting 
Four different modes of operation
Cont…. 
Wide range of BAUD rates 
SCON(serial control): used to define operating modes 
and some control functions 
PCON(power control): used to modify the baud rate. 
If bit D7 (SMOD) = 1 , then baud rate is doubled 
If SMOD = 0 , then baud rate is as specified by the 
programmer
Serial control (SCON) Register 
7 6 5 4 3 2 1 0 
SM0 SM1 SM2 REN TB8 RB8 TI RI 
SM0 SM1 MODE operation transmit rate 
0 0 0 shift register fixed (xtal/12) 
0 1 1 8 bit UART variable (timer1) 
1 0 2 9 bit UART fixed (xtal/32 or 
xtal/64) 
1 1 3 9 bit UART variable (timer1) 
SM0 : mode specifier 
SM1 : mode specifier 
SM2 : used for multi processor communication 
REN : receive enable (by software enable/disable) 
TB8 : transmit bit8 (not widely used) 
RB8 : receive bit 8 (not widely used) 
TI : transmit interrupt flag set by HW after send , clear by SW 
RI : receive interrupt flag set by HW after received ,clear by SW
BAUD RATE CALCULATION? 
To allow data transfer between the PC and an 8051 system 
without any error, we must make sure that the baud rate of 
8051 system matches the baud rate of the PC’s COM port. 
2400 baud =2400 signals per second 
= 2400Hz
Register values for various baud 
rates 
BAUD rate TH1 (decimal) TH1 (HEX) 
9600 -3 FD 
4800 -6 FA 
2400 -12 F4 
1200 -24 E8
With XTAL = 11.0592 MHz, find the TH1 value needed to have the 
following baud rates. (a) 9600 (b) 2400 (c) 1200 
Solution: 
The machine cycle frequency of 8051 = 11.0592 / 12 = 921.6 kHz, 
and 921.6 kHz / 32 = 28,800 Hz is frequency by UART to timer 1 to 
set baud rate. 
(a) 28,800 / 3 = 9600 where -3 = FD (hex) is loaded into TH1 
(b) 28,800 / 12 = 2400 where -12 = F4 (hex) is loaded into TH1 
(c) 28,800 / 24 = 1200 where -24 = E8 (hex) is loaded into TH1 
Notice that dividing 1/12 of the crystal frequency by 32 is the default 
value upon activation of the 8051 RESET pin.
SBUF register 
SBUF is an 8-bit register used solely 
for serial communication 
1. For a byte data to be transferred via the TxD line, it 
must be placed in the SBUF register. 
2. SBUF holds the byte of data when it is received by 
8051 RxD line
Programming the 8051 to transfer data 
serially 
1. TMOD register is loaded with the value 
20H, indicating the use of timer 1 in mode 2 
(8-bit auto-reload) to set baud rate 
2. The TH1 is loaded with one of the values 
to set baud rate for serial data transfer 
3. The SCON register is loaded with the value 
50H, indicating serial mode 1, where an 8- 
bit data is framed with start and stop bits 
4. TR1 is set to 1 to start timer 1
5. TI is cleared by CLR TI instruction 
6. The character byte to be transferred 
serially is written into SBUF register 
7. The TI flag bit is monitored with the use of 
instruction JNB TI,xx to see if the 
character has been transferred completely 
8. To transfer the next byte, go to step 5
Ex. Write a program for the 8051 to transfer 
letter “A” serially at 4800 
baud, continuously. 
Soln: 
MOV TMOD, # 20 ;timer 1,mode 2(auto reload) 
MOV TH1, # -6 ;4800 baud rate 
MOV SCON, # 50H ;8-bit, 1 start and 1 stop bit 
SETB TR1 ;start timer 1 
AGAIN: MOV SBUF,#”A” ;letter “A” to transfer 
HERE: JNB TI, HERE ;wait for the last bit 
CLR TI ;clear TI for next char 
SJMP AGAIN ;keep sending A
Write a C program for 8051 to transfer the letter “A” 
serially at 4800baud continuously. Use 8-bit data and 1 
stop bit. 
#include <reg51.h> 
void main(void) 
{ 
TMOD=0x20; //use Timer 1, mode 2 
TH1=0xFA; //4800 baud rate 
SCON=0x50; 
TR1=1; 
while (1) { 
SBUF=‘A’; //place value in buffer 
while (TI==0); 
TI=0; 
} 
}
programming the 8051 to receive 
character bytes serially 
1. TMOD register is loaded with the value 
20H, indicating the use of timer 1 in mode 2 
(8-bit auto-reload) to set baud rate. 
2. TH1 is loaded to set baud rate. 
3. The SCON register is loaded with the value 
50H, indicating serial mode 1, where an 
8-bit data is framed with start and stop bits 
4. TR1 is set to 1 to start timer 1
5. RI is cleared by CLR RI instruction 
6. The RI flag bit is monitored with the use of 
instruction JNB RI,xx to see if an entire 
character has been received yet 
7. When RI is raised, SBUF has the byte, its 
contents are moved into a safe place 
8. To receive the next character, go to step 5
Ex. 
Write a program for the 8051 to receive 
bytes of data serially, and put them in 
P1, set the baud rate at 4800, 8-bit 
data, and 1 stop bit.
Soln: 
MOV TMOD, #20H ;timer 1,mode2(auto reload) 
MOV TH1, #-6 ;4800 baud rate 
MOV SCON, #50H ;8-bit, 1 stop, REN enabled 
SETB TR1 ;start timer 1 
HERE: JNB RI, HERE ;wait for char to come in 
MOV A, SBUF ;saving incoming byte in A 
MOV P1, A ;send to port 1 
CLR RI ;get ready to receive next byte 
SJMP HERE ;keep getting data
Program the 8051 in C to receive bytes of data serially and put 
them in P1. Set the baud rate at 4800, 8-bit data, and 1 stop bit. 
#include <reg51.h> 
void main(void) 
{ 
unsigned char mybyte; 
TMOD=0x20; //use Timer 1, mode 2 
TH1=0xFA; //4800 baud rate 
SCON=0x50; 
TR1=1; //start timer 
while (1) 
{ //repeat forever 
while (RI==0); //wait to receive 
mybyte=SBUF; //save value 
P1=mybyte ; //write value to port 
RI=0; 
}}
12 mt06ped019

More Related Content

What's hot

8051 serial communication1
8051 serial communication1 8051 serial communication1
8051 serial communication1 vijaydeepakg
 
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50Ruthvik Vaila
 
Introduction to pll
Introduction to pllIntroduction to pll
Introduction to pllsartaj ahmed
 
Fun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksFun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksRitesh Kanjee
 
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3KanchanPatil34
 
Arrow Devices USB 2.0 Concepts
Arrow Devices USB 2.0 ConceptsArrow Devices USB 2.0 Concepts
Arrow Devices USB 2.0 ConceptsArrow Devices
 
Asynchronous Serial Communication and standards
Asynchronous Serial Communication and standardsAsynchronous Serial Communication and standards
Asynchronous Serial Communication and standardsMathivanan Natarajan
 
Llpc2148 sci
Llpc2148 sciLlpc2148 sci
Llpc2148 scianishgoel
 
Pll in lpc2148
Pll in lpc2148Pll in lpc2148
Pll in lpc2148Aarav Soni
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 
Mridul_Verma_Intern_Tech_Adityaa_UART
Mridul_Verma_Intern_Tech_Adityaa_UARTMridul_Verma_Intern_Tech_Adityaa_UART
Mridul_Verma_Intern_Tech_Adityaa_UARTMridul Verma
 
FPGA implementation of synchronous and asynchronous counter and simulation of...
FPGA implementation of synchronous and asynchronous counter and simulation of...FPGA implementation of synchronous and asynchronous counter and simulation of...
FPGA implementation of synchronous and asynchronous counter and simulation of...ASHIMA GUPTA
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communicationasteriskbimal
 
Serial Communication Part-16
Serial Communication Part-16Serial Communication Part-16
Serial Communication Part-16Techvilla
 
8051 Instruction Set
8051 Instruction Set8051 Instruction Set
8051 Instruction SetStupidsid.com
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGTotal Project Solutions
 
Phase Locked Loops (PLL) 1
Phase Locked Loops (PLL) 1Phase Locked Loops (PLL) 1
Phase Locked Loops (PLL) 1Pei-Che Chang
 

What's hot (20)

8051 serial communication1
8051 serial communication1 8051 serial communication1
8051 serial communication1
 
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
MEASUREMENT AND DISPLAY OF THE MAINS FREQUENCY USING PIC18F4520/50
 
Introduction to pll
Introduction to pllIntroduction to pll
Introduction to pll
 
Fun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksFun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol Works
 
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
 
Arrow Devices USB 2.0 Concepts
Arrow Devices USB 2.0 ConceptsArrow Devices USB 2.0 Concepts
Arrow Devices USB 2.0 Concepts
 
Asynchronous Serial Communication and standards
Asynchronous Serial Communication and standardsAsynchronous Serial Communication and standards
Asynchronous Serial Communication and standards
 
Uart
UartUart
Uart
 
Llpc2148 sci
Llpc2148 sciLlpc2148 sci
Llpc2148 sci
 
Pll in lpc2148
Pll in lpc2148Pll in lpc2148
Pll in lpc2148
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 
Mridul_Verma_Intern_Tech_Adityaa_UART
Mridul_Verma_Intern_Tech_Adityaa_UARTMridul_Verma_Intern_Tech_Adityaa_UART
Mridul_Verma_Intern_Tech_Adityaa_UART
 
Rip 1 rip 2
Rip 1 rip 2Rip 1 rip 2
Rip 1 rip 2
 
FPGA implementation of synchronous and asynchronous counter and simulation of...
FPGA implementation of synchronous and asynchronous counter and simulation of...FPGA implementation of synchronous and asynchronous counter and simulation of...
FPGA implementation of synchronous and asynchronous counter and simulation of...
 
8051 serial communication
8051 serial communication8051 serial communication
8051 serial communication
 
Serial Communication Part-16
Serial Communication Part-16Serial Communication Part-16
Serial Communication Part-16
 
Serial data transfer
Serial data transferSerial data transfer
Serial data transfer
 
8051 Instruction Set
8051 Instruction Set8051 Instruction Set
8051 Instruction Set
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACING
 
Phase Locked Loops (PLL) 1
Phase Locked Loops (PLL) 1Phase Locked Loops (PLL) 1
Phase Locked Loops (PLL) 1
 

Similar to 12 mt06ped019

Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....ANKUSH445845
 
Seminar on serial communication
Seminar on serial communicationSeminar on serial communication
Seminar on serial communicationSamarth Patel
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfSPonmalar1
 
8051 serialp port
8051 serialp port8051 serialp port
8051 serialp portTeju Kotti
 
serial-200505101453.pdf
serial-200505101453.pdfserial-200505101453.pdf
serial-200505101453.pdfKiranG731731
 
Serial communication in 8051 microcontroller
Serial communication in 8051 microcontrollerSerial communication in 8051 microcontroller
Serial communication in 8051 microcontrollerIshwarNirale2
 
8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptxmaheswariM7
 
Universal Serial Communication Interface
Universal Serial Communication InterfaceUniversal Serial Communication Interface
Universal Serial Communication InterfaceSandesh Agrawal
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communicationsinaankhalil
 
8051 microcontroller notes continuous
8051 microcontroller notes continuous 8051 microcontroller notes continuous
8051 microcontroller notes continuous THANDAIAH PRABU
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)cairo university
 
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD CoverterUniversal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD CoverterTejas Shetye
 
Vlsi implementation ofdm
Vlsi implementation ofdmVlsi implementation ofdm
Vlsi implementation ofdmManas Verma
 
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdfShashiKiran664181
 
Serial Communication Uart soc
Serial Communication  Uart socSerial Communication  Uart soc
Serial Communication Uart socSatyam Sharma
 

Similar to 12 mt06ped019 (20)

8051 serial communication-UART
8051 serial communication-UART8051 serial communication-UART
8051 serial communication-UART
 
Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....
 
Seminar on serial communication
Seminar on serial communicationSeminar on serial communication
Seminar on serial communication
 
EC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdfEC8691 - UNIT 5.pdf
EC8691 - UNIT 5.pdf
 
8051 serialp port
8051 serialp port8051 serialp port
8051 serialp port
 
Chap10
Chap10Chap10
Chap10
 
serial-200505101453.pdf
serial-200505101453.pdfserial-200505101453.pdf
serial-200505101453.pdf
 
Serial Communication in 8051
Serial Communication in 8051Serial Communication in 8051
Serial Communication in 8051
 
Serial communication in 8051 microcontroller
Serial communication in 8051 microcontrollerSerial communication in 8051 microcontroller
Serial communication in 8051 microcontroller
 
8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx8051 SERIAL PORTS.pptx
8051 SERIAL PORTS.pptx
 
Class10
Class10Class10
Class10
 
Universal Serial Communication Interface
Universal Serial Communication InterfaceUniversal Serial Communication Interface
Universal Serial Communication Interface
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communication
 
8051 microcontroller notes continuous
8051 microcontroller notes continuous 8051 microcontroller notes continuous
8051 microcontroller notes continuous
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)
 
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD CoverterUniversal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
 
Vlsi implementation ofdm
Vlsi implementation ofdmVlsi implementation ofdm
Vlsi implementation ofdm
 
020419.pdf
020419.pdf020419.pdf
020419.pdf
 
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
 
Serial Communication Uart soc
Serial Communication  Uart socSerial Communication  Uart soc
Serial Communication Uart soc
 

12 mt06ped019

  • 1. Seminar on SERIAL COMMUNICATION session 1 Presented by— somu chaitanya 12MT06PED019
  • 2. Basics of communication PARALLEL often 8 or more lines (wire conductors) are used to transfer data to a device that is only a few feet away SERIAL to transfer to a device located many meters away, the serial method is used  The data is sent one bit at a time
  • 3. Parallel: expensive-short distance-fast – no modulation Serial: cheaper- long(two diff cities by modem) – slow
  • 4. Why serial???? To reduce the cost of cabling Minimise the effect of noise Availability of suitable communication media Inherent device characteristics Small connector Distributed computing Sensor networking
  • 5. Types of serial data transfer
  • 6. Basics of serial At the transmitting end, the byte of data must be converted to serial bits using parallel-in-serial-out shift register At the receiving end, there is a serial-in-parallel-out shift register to receive the serial data When the distance is short, the digital signal can be transferred as it is on a simple wire and requires no modulation If data is to be transferred on the telephone line, it must be converted from 0s and 1s to audio tones. This conversion is performed by a device called “modem”
  • 7. Serial data communication uses two methods: Synchronous – transfers a block at a time Asynchronous – transfers a single byte at a time IC chips used to write a program are UART (universal asynchronous Receiver transmitter) USART (universal synchronous-asynchronous Receiver-transmitter)
  • 8. ASYNCHRONOUS MODE start and stop bit In asynchronous transmission When there is no transfer the signal is high Transmission begins with a start (low) bit LSB first Finally 1 stop bit (high) Data transfer rate (baud rate) is stated in bps
  • 9.
  • 10. Advantage: Frequency tolerant. Disadvantage overhead
  • 11. SYNCHRONOUS MODE: Advantage: Overhead is small. Disadvantage: • Clock frequency should be identical.
  • 12. DATA TRANSFER RATE How fast data is transferred? Three methods to describe the speed. Data Rate(bps) Number of bits transferred per second. Baud rate(Hz) Number of signal changes per second. Effective Data Rate Number of actual data bits transferred per second
  • 13. Data Transfer Rate  IBM PC/XT could transfer data at the rate of 100 to 9600 bps Pentium-based PCs transfer data at rates as high as 56K bps In asynchronous serial data communication, the baud rate is limited to 100K bps
  • 14. Key features of 8051 serial interface Full-duplex communication Serial circuit is provided with two buffers– 1. For communication b/w the microprocessor 2. For serially taking data from serial line SFR (also called as SBUF ) whose mnemonics is same for both receiving and transmitting Four different modes of operation
  • 15. Cont…. Wide range of BAUD rates SCON(serial control): used to define operating modes and some control functions PCON(power control): used to modify the baud rate. If bit D7 (SMOD) = 1 , then baud rate is doubled If SMOD = 0 , then baud rate is as specified by the programmer
  • 16. Serial control (SCON) Register 7 6 5 4 3 2 1 0 SM0 SM1 SM2 REN TB8 RB8 TI RI SM0 SM1 MODE operation transmit rate 0 0 0 shift register fixed (xtal/12) 0 1 1 8 bit UART variable (timer1) 1 0 2 9 bit UART fixed (xtal/32 or xtal/64) 1 1 3 9 bit UART variable (timer1) SM0 : mode specifier SM1 : mode specifier SM2 : used for multi processor communication REN : receive enable (by software enable/disable) TB8 : transmit bit8 (not widely used) RB8 : receive bit 8 (not widely used) TI : transmit interrupt flag set by HW after send , clear by SW RI : receive interrupt flag set by HW after received ,clear by SW
  • 17. BAUD RATE CALCULATION? To allow data transfer between the PC and an 8051 system without any error, we must make sure that the baud rate of 8051 system matches the baud rate of the PC’s COM port. 2400 baud =2400 signals per second = 2400Hz
  • 18. Register values for various baud rates BAUD rate TH1 (decimal) TH1 (HEX) 9600 -3 FD 4800 -6 FA 2400 -12 F4 1200 -24 E8
  • 19. With XTAL = 11.0592 MHz, find the TH1 value needed to have the following baud rates. (a) 9600 (b) 2400 (c) 1200 Solution: The machine cycle frequency of 8051 = 11.0592 / 12 = 921.6 kHz, and 921.6 kHz / 32 = 28,800 Hz is frequency by UART to timer 1 to set baud rate. (a) 28,800 / 3 = 9600 where -3 = FD (hex) is loaded into TH1 (b) 28,800 / 12 = 2400 where -12 = F4 (hex) is loaded into TH1 (c) 28,800 / 24 = 1200 where -24 = E8 (hex) is loaded into TH1 Notice that dividing 1/12 of the crystal frequency by 32 is the default value upon activation of the 8051 RESET pin.
  • 20. SBUF register SBUF is an 8-bit register used solely for serial communication 1. For a byte data to be transferred via the TxD line, it must be placed in the SBUF register. 2. SBUF holds the byte of data when it is received by 8051 RxD line
  • 21. Programming the 8051 to transfer data serially 1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit auto-reload) to set baud rate 2. The TH1 is loaded with one of the values to set baud rate for serial data transfer 3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8- bit data is framed with start and stop bits 4. TR1 is set to 1 to start timer 1
  • 22. 5. TI is cleared by CLR TI instruction 6. The character byte to be transferred serially is written into SBUF register 7. The TI flag bit is monitored with the use of instruction JNB TI,xx to see if the character has been transferred completely 8. To transfer the next byte, go to step 5
  • 23. Ex. Write a program for the 8051 to transfer letter “A” serially at 4800 baud, continuously. Soln: MOV TMOD, # 20 ;timer 1,mode 2(auto reload) MOV TH1, # -6 ;4800 baud rate MOV SCON, # 50H ;8-bit, 1 start and 1 stop bit SETB TR1 ;start timer 1 AGAIN: MOV SBUF,#”A” ;letter “A” to transfer HERE: JNB TI, HERE ;wait for the last bit CLR TI ;clear TI for next char SJMP AGAIN ;keep sending A
  • 24. Write a C program for 8051 to transfer the letter “A” serially at 4800baud continuously. Use 8-bit data and 1 stop bit. #include <reg51.h> void main(void) { TMOD=0x20; //use Timer 1, mode 2 TH1=0xFA; //4800 baud rate SCON=0x50; TR1=1; while (1) { SBUF=‘A’; //place value in buffer while (TI==0); TI=0; } }
  • 25. programming the 8051 to receive character bytes serially 1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit auto-reload) to set baud rate. 2. TH1 is loaded to set baud rate. 3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-bit data is framed with start and stop bits 4. TR1 is set to 1 to start timer 1
  • 26. 5. RI is cleared by CLR RI instruction 6. The RI flag bit is monitored with the use of instruction JNB RI,xx to see if an entire character has been received yet 7. When RI is raised, SBUF has the byte, its contents are moved into a safe place 8. To receive the next character, go to step 5
  • 27. Ex. Write a program for the 8051 to receive bytes of data serially, and put them in P1, set the baud rate at 4800, 8-bit data, and 1 stop bit.
  • 28. Soln: MOV TMOD, #20H ;timer 1,mode2(auto reload) MOV TH1, #-6 ;4800 baud rate MOV SCON, #50H ;8-bit, 1 stop, REN enabled SETB TR1 ;start timer 1 HERE: JNB RI, HERE ;wait for char to come in MOV A, SBUF ;saving incoming byte in A MOV P1, A ;send to port 1 CLR RI ;get ready to receive next byte SJMP HERE ;keep getting data
  • 29. Program the 8051 in C to receive bytes of data serially and put them in P1. Set the baud rate at 4800, 8-bit data, and 1 stop bit. #include <reg51.h> void main(void) { unsigned char mybyte; TMOD=0x20; //use Timer 1, mode 2 TH1=0xFA; //4800 baud rate SCON=0x50; TR1=1; //start timer while (1) { //repeat forever while (RI==0); //wait to receive mybyte=SBUF; //save value P1=mybyte ; //write value to port RI=0; }}