{"id":243,"date":"2018-07-27T06:10:02","date_gmt":"2018-07-27T06:10:02","guid":{"rendered":"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=243"},"modified":"2018-07-27T06:15:59","modified_gmt":"2018-07-27T06:15:59","slug":"serial-port-programming-in-embedded-c","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/chapter\/serial-port-programming-in-embedded-c\/","title":{"rendered":"Serial Port Programming in Embedded C"},"content":{"raw":"<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this lecture basics of serial port communication in 8051 will be discussed. The Control register in 8051 will be visited. Embedded C program for Serial port communication will be discussed in detail with examples.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong><strong>Serial Vs Parallel<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Data transferred by computer occurs in two ways. They are parallel and serial communication. Parallel Communication has 8 or more lines. It is used for transfer of data to a device that is only a short distance, while serial communication is used to transfer data over a long distance.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The data is sent one bit at a time in serial communication, whereas multiple bits are sent simultaneously in parallel communication. The difference between serial communication and parallel communication is shown in Figure 1.<\/p>\r\n<img class=\"size-full wp-image-246 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-136.png\" alt=\"\" width=\"555\" height=\"203\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>1.1<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>Serial Communication<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The transmitter converts a byte of data into serial bits using parallel-in-serial-out shift register, while the receiver has a serial-in-parallel-out shift register to receive the serial data and pack them into a byte. For a short distance, the digital signal can be transferred on a simple wire without modulation. To transfer data over a long distance, some form of modulation may be required. For example, to transfer data on the telephone line, it must be converted from 0s and 1s to audio tones. The device which performs conversion of 0s and 1s to audio tones, and back, is called a modem, \u201cModulator\/demodulator\u201d.<\/p>\r\n&nbsp;\r\n\r\nThe serial communication uses two techniques for communication. They are\r\n\r\n\u25cf\u00a0\u00a0\u00a0\u00a0 Synchronous- transfer block of data(characters) at a time\r\n\r\n\u25cf\u00a0\u00a0\u00a0\u00a0 Asynchronous- transfer single byte at a time\r\n\r\n&nbsp;\r\n\r\nThis communication can be done by the following hardware:\r\n\r\n\u25cf\u00a0\u00a0\u00a0\u00a0 USART (Universal Synchronous-Asynchronous Receiver-Transmitter)\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">\u25cf\u00a0\u00a0\u00a0\u00a0 UART (Universal Asynchronous Receiver Transmitter) The 8051 chip has a built-in UART.<\/span>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Asynchronous communication is used for character-oriented transmissions, but each character is placed in between start and stop bits; this is called framing. The start bit is always one bit and the stop bit can be one or two bits. The start bit is always a 0 (low), while the stop bit(s) is 1 (high) and the LSB is sent out first. Block-oriented data transfers use the synchronous method. Data transfer rate in serial data communication is mentioned in bps (bits per second) or baud rate.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.2<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>RS232 standards<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is the most widely used serial I\/O interfacing standard for serial communication. The input and output voltage levels are not TTL compatible. The bit-value of 1 is represented as -3 to -25 V and the value0 is represented as +3 to +25 V, while -3 to +3 is undefined. To connect RS232 to a microcontroller system, it must use voltage converters such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and vice versa. MAX232 IC chips are commonly referred to as line drivers.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.3 8051 connections to RS232<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">8051 has two pins used for transferring and receiving data serially. They are TxD and RxD pins. TxD and RxD are part of the port 3 group (P3.0 and P3.1), while pin 11 (P3.1) of 8051 is assigned to TxD. The pin 10 (P3.0) of 8051 is assigned to RxD. These pins are TTL compatible. They require a line driver to make them RS232 compatible. The driver used for this is MAX232 chip.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.4 Serial Communication Registers<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>SBUF Register:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is an 8-bit register used for serial communication. To transmit a byte of data via the TxD line, it must be placed in the SBUF register. When a byte is written into SBUF, it is framed with the start and stop bits and transferred serially via the TxD line. SBUF holds the byte of data when it is received by 8051 RxD line. When the bits are received serially via RxD, 8051 deframes it by removing the stop and start bits, making a byte out of the data received, and then places it in SBUF register.<\/p>\r\n&nbsp;\r\n\r\n<strong>SCON (serial control) register:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is an 8-bit register used to program start bit, stop bit, and data bits of data for framing, among other things. In this SM0 and SM1 are used to determine the mode. If (SM0,SM1) is (0,0) then it is mode 0, in this mode the serial port function as half duplex serial port with fixed baud rate.If (SM0,SM1) is (0,1) it is mode1,in this mode the serial port function as full duplex serial port with variable baud rate. If (SM0,SM1) is (1,0) then it is mode 2, in this mode the serial port function as full duplex serial port with a baud rate of either 1\/32 or 1\/64 of the oscillator frequency. If (SM0,SM1) is (1,1) then it is mode 3.The mode-3 is same as mode-2, except the baud rate.In all these modes, only mode 1 is important. When mode 1 is chosen, the following bits are compatible with the COM port of PCs. They are 8 bits of data with 1 stop bit, and 1 start bit. The mode 1 allows the baud rate to be variable and is set by Timer 1 of the 8051. For each\u00a0<span style=\"font-size: 1em;text-align: initial\">character a total of 10 bits are transferred, where the first bit is the start bit, followed by 8 bits of data, and finally 1 stop bit.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">REN is the receive enable. If REN=1, it allows 8051 to receive data on the RxD. If 8051 is to both transfer and receive data, REN must be set to 1. If REN=0, the receiver is disabled and TB8 is used for serial modes 2 and 3. The figure 2 shown below specifies the bits of the SCON register.<\/p>\r\n<img class=\"size-full wp-image-247 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-137.png\" alt=\"\" width=\"715\" height=\"322\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>1.5<\/strong>\u00a0<strong>Use of Baud rate in 8051<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Baud rate in 8051 is programmable. It is done with the help of Timer 1. Timer 1 must be programmed in mode 2, that is, 8-bit, auto-reload. We must make sure that the baud rate of the 8051 system matches the baud rate of the system used for communication.<\/p>\r\n&nbsp;\r\n\r\nRelationship between the crystal frequency and the baud rate in the 8051 is as follows:\r\n\r\n\u25aa\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8051 divides the crystal frequency by 12 to get the machine cycle frequency.\r\n\r\n\u25aa\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Load FD\/FA\/F4\/E8 in TH1 to get 9600\/4800\/2400\/1200 baud rate.\r\n\r\n&nbsp;\r\n\r\n<strong>1.6<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>Steps to send data serially in serial port communication<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe following are the steps to send the data serially in serial port communication:\r\n\r\n&nbsp;\r\n\r\n1. Set baud rate by loading TMOD register with the value 20H; this indicates timer 1 in mode 2 (8-bit auto-reload) to set baud rate.\r\n\r\n2. The TH1 is loaded with proper values to set baud rate for serial data transfer.\r\n\r\n3.\u00a0\u00a0\u00a0 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.\r\n\r\n4.\u00a0\u00a0\u00a0 TR1 is set to 1 to start timer 1.\r\n\r\n5.\u00a0\u00a0\u00a0 Transmit Interrupt(TI) is cleared by CLR TI instruction.\r\n\r\n6.\u00a0\u00a0\u00a0 The character byte to be transferred serially is written into SBUF register.\r\n\r\n7.\u00a0\u00a0\u00a0 The TI flag bit is monitored to see if the character has been transferred completely.\r\n\r\n8.\u00a0\u00a0\u00a0 To transfer the next byte, go to step 5.\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>1.7<\/strong>\u00a0<strong>Importance of the TI flag:<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe following steps are the importance of TI flag in 8051 serial port communication\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">\u25cf\u00a0\u00a0\u00a0\u00a0 Check the TI flag bit, we know whether or not 8051 is ready to transfer another byte.<\/p>\r\n<p style=\"text-align: justify\">\u25cf\u00a0\u00a0\u00a0\u00a0 TI flag bit is raised by the 8051 after transfer of data.<\/p>\r\n<p style=\"text-align: justify\">\u25cf\u00a0\u00a0\u00a0\u00a0 TI flag is cleared by the programmer by instructions like \u201cCLR TI\u201d.<\/p>\r\n&nbsp;\r\n\r\n\u25cf\u00a0\u00a0\u00a0\u00a0 Writing a byte into SBUF before the TI flag bit is raised, may lead to loss of a portion of the byte being transferred.\r\n\r\n&nbsp;\r\n\r\n<strong>1.8\u00a0<\/strong>\u00a0<strong>Steps to receive data serially in serial port communication<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe following are the steps to receive the data serially in the serial port communication:\r\n\r\n&nbsp;\r\n\r\n1. Set baud rate by loading TMOD register with the value 20H; this indicates setting of timer 1 in mode 2 (8-bit auto-reload) to set baud rate.\r\n\r\n2. The TH1 is loaded with proper values to set baud rate.\r\n<p style=\"text-align: justify\">3.\u00a0 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.<\/p>\r\n4.\u00a0\u00a0\u00a0 TR1 is set to 1 to start timer 1.\r\n\r\n5.\u00a0\u00a0\u00a0 Receive Interrupt(RI) is cleared by CLR RI instruction.\r\n\r\n6.\u00a0\u00a0\u00a0 The RI flag bit is monitored to see if an entire character has been received yet.\r\n\r\n7.\u00a0\u00a0\u00a0 When RI is raised, SBUF has the byte, its contents are moved into a safe place.\r\n\r\n8.\u00a0\u00a0\u00a0 To receive next character, go to step 5.\r\n\r\n&nbsp;\r\n\r\n<strong>1.9<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>Importance of the RI flag:<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe following point to the importance of RI flag in 8051 serial port communication:\r\n\r\n&nbsp;\r\n\r\n1.\u00a0\u00a0\u00a0 It receives the start bit, next bit is the first bit of the character about to be received.\r\n\r\n2.\u00a0\u00a0\u00a0 When the last bit is received, a byte is formed and placed in the SBUF register.\r\n\r\n3.\u00a0\u00a0\u00a0 When the stop bit is received, it makes RI = 1 indicating that the entire character byte has been received and can be written before being overwritten.\r\n\r\n4.\u00a0\u00a0\u00a0 When RI=1, received byte is in the SBUF register, copy SBUF contents to a safe place.\r\n\r\n5.\u00a0\u00a0\u00a0 After the SBUF contents are copied, the RI flag bit must be cleared to 0.\r\n\r\n&nbsp;\r\n\r\nWe will now look at programming these using Embedded C.\r\n\r\n&nbsp;\r\n\r\n<strong>2.\u00a0<\/strong><strong>8051 Embedded C Programming for Serial Port Communication<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">SFR registers of 8051 are accessible directly in 8051 C compilers by using reg51.h. It has already been described in the previous modules. Example 1 shows how to program the serial port in 8051 using Embedded C. For testing operation, HyperTerminal is used for this example.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example 1<\/strong>\r\n\r\n&nbsp;\r\n\r\nWrite a C program for 8051 to transfer the letter \u201cA\u201d serially at 4800 baud continuously.\r\n\r\n<\/div>\r\n<div>\r\n\r\nUse 8-bit data and 1 stop bit.\r\n\r\n<strong>Solution:<\/strong>\r\n\r\n#include &lt;reg51.h&gt;\r\n\r\nvoid main(void){\r\n\r\nTMOD=0x20; \/\/use Timer 1, mode 2\r\n\r\nTH1=0xFA; \/\/4800 baud rate\r\n\r\nSCON=0x50;\r\n\r\nTR1=1;\r\n\r\nwhile (1) {\r\n\r\nSBUF=\u2018A\u2019; \/\/place value in buffer\r\n\r\nwhile (TI==0);\r\n\r\nTI=0;\r\n\r\n}\r\n\r\n}\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Example 2 described below gives the details about how to transfer the message serially with 9600 baud continuously.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example 2<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Write an 8051 C program to transfer the message \u201cYES\u201d serially at 9600 baud, 8-bit data, 1 stop bit. Do this continuously.<\/p>\r\n&nbsp;\r\n\r\n<strong>Solution:<\/strong>\r\n\r\n&nbsp;\r\n\r\n#include &lt;reg51.h&gt;\r\n\r\n&nbsp;\r\n\r\nvoid SerTx(unsigned char);\r\n\r\nvoid main(void){\r\n\r\nTMOD=0x20; \/\/use Timer 1, mode 2\r\n\r\nTH1=0xFD; \/\/9600 baud rate\r\n\r\nSCON=0x50;\r\n\r\nTR1=1; \/\/start timer\r\n\r\nwhile (1) {\r\n\r\nSerTx(\u2018Y\u2019);\r\n\r\nSerTx(\u2018E\u2019);\r\n\r\nSerTx(\u2018S\u2019);\r\n\r\n}\r\n\r\n}\r\n\r\nvoid SerTx(unsigned char x){\r\n\r\nSBUF=x; \/\/place value in buffer\r\n\r\nwhile (TI==0); \/\/wait until transmitted\r\n\r\nTI=0;\r\n\r\n}\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Example 3 described below gives the details about how to receive the data serially and put in Port P1 with 4800 baud and 1 stop bit. Here, Timer 1 in mode 2 is used for stopping the bit while receiving the data. The received data stored in the SBUF is then written to port P1.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example 3<\/strong>\r\n\r\n<\/div>\r\n<div>\r\n<p style=\"text-align: justify\">Program the 8051 in C to receive bytes of data serially and put them in P1. Set the baud rate at 4800; use 8-bit data, and 1 stop bit.<\/p>\r\n&nbsp;\r\n\r\n#include &lt;reg51.h&gt;\r\n\r\nvoid main(void){\r\n\r\nunsigned char mybyte;\r\n\r\nTMOD=0x20; \/\/use Timer 1, mode 2\r\n\r\nTH1=0xFA; \/\/4800 baud rate\r\n\r\nSCON=0x50;\r\n\r\nTR1=1; \/\/start timer\r\n\r\nwhile (1) { \/\/repeat forever\r\n\r\nwhile (RI==0); \/\/wait to receive\r\n\r\nmybyte=SBUF; \/\/save value\r\n\r\nP1=mybyte; \/\/write value to port\r\n\r\nRI=0;\r\n\r\n}\r\n\r\n}\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Example 4 described below gives the details about sending two messages to serial port with 28,800 and 56K baud. Here Timer 1 in mode 2 is used. The data is stored in the SBUF and then it waits to transmit to the corresponding destination.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example 4<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Write an 8051 C Program to send the two messages \u201cNormal Speed\u201d and \u201cHigh Speed\u201d to the serial port. Assuming that SW is connected to pin P2.0, monitor its status and set the baud rate as follows:<\/p>\r\n&nbsp;\r\n\r\nSW = 0, 28,800 baud rate\r\n\r\nSW = 1, 56K baud rate\r\n\r\nAssume that XTAL = 11.0592 MHz for both cases.\r\n\r\n&nbsp;\r\n\r\n<strong>Solution:<\/strong>\r\n\r\n#include &lt;reg51.h&gt;\r\n\r\n&nbsp;\r\n\r\nsbit MYSW=P2^0; \/\/input switch\r\n\r\nvoid main(void){\r\n\r\nunsigned char z;\r\n\r\nunsigned char Mess1[]=\u201cNormal Speed\u201d;\r\n\r\nunsigned char Mess2[]=\u201cHigh Speed\u201d;\r\n\r\nTMOD=0x20; \/\/use Timer 1, mode 2\r\n\r\nTH1=0xFF; \/\/28800 for normal\r\n\r\nSCON=0x50;\r\n\r\nTR1=1; \/\/start timer\r\n\r\nif(MYSW==0) {\r\n\r\nfor (z=0;z&lt;12;z++) {\r\n\r\nSBUF=Mess1[z]; \/\/place value in buffer\r\n\r\nwhile(TI==0); \/\/wait for transmit\r\n\r\nTI=0;\r\n\r\n}\r\n\r\n}\r\n\r\nelse {\r\n\r\nPCON=PCON|0x80; \/\/for high speed of 56K\r\n\r\nfor (z=0;z&lt;10;z++) {\r\n\r\nSBUF=Mess2[z]; \/\/place value in buffer\r\n\r\n<\/div>\r\n&nbsp;\r\n<div>\r\n\r\nwhile(TI==0); \/\/wait for transmit\r\n\r\nTI=0;\r\n\r\n}\r\n\r\n}\r\n\r\n}\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Example 5 described below gives the details about transferring the letter A serially with 4,800 baud continuously. Here Timer 1 in mode 2 is used to set the baud rate. The data is stored in the SBUF and new addresses for DS89C4x0 chip are declared using SFR registers using sfr keyword.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example 5<\/strong>\r\n<p style=\"text-align: justify\"><\/p>\r\n<p style=\"text-align: justify\">Write a C program for the DS89C4x0 to transfer the letter \u201cA\u201d serially at 4800 baud continuously. Use the second serial port with 8-bit data and 1 stop bit. (note: We can only use Timer 1 to set the baud rate).<\/p>\r\n<strong>Solution:<\/strong>\r\n\r\n#include &lt;reg51.h&gt;\r\n\r\nsfr SBUF1=0xC1;\r\n\r\nsfr SCON1=0xC0;\r\n\r\nsbit TI1=0xC1;\r\n\r\nvoid main(void){\r\n\r\nTMOD=0x20; \/\/use Timer 1, mode 2\r\n\r\nTH1=0xFA; \/\/4800 baud rate\r\n\r\nSCON1=0x50; \/\/use 2nd serial port SCON1\r\n\r\nTR1=1; \/\/start timer\r\n\r\nwhile (1) {\r\n\r\nSBUF1=\u2018A\u2019; \/\/use 2nd serial port SBUF1\r\n\r\nwhile (TI1==0); \/\/wait for transmit\r\n\r\nTI1=0;\r\n\r\n}}\r\n\r\n&nbsp;\r\n\r\nExample 6 described below gives the details about receiving the data serially with 9,600 bauds via second serial port. Here Timer 1 in mode 2 is used to set the baud rate.\r\n\r\n&nbsp;\r\n\r\n<strong>Example 6<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Program the DS89C4x0 in C to receive bytes of data serially via the second serial port and put them in P1. Set the baud rate at 9600, 8-bit data and 1 stop bit. Use Timer 1 for baud rate generation.<\/p>\r\n&nbsp;\r\n\r\n<strong>Solution:<\/strong>\r\n\r\n#include &lt;reg51.h&gt;\r\n\r\nsfr SBUF1=0xC1;\r\n\r\nsfr SCON1=0xC0;\r\n\r\nsbit RI1=0xC0;\r\n\r\nvoid main(void){\r\n\r\nunsigned char mybyte;\r\n\r\nTMOD=0x20; \/\/use Timer 1, mode 2\r\n\r\nTH1=0xFD; \/\/9600 baud rate\r\n\r\nSCON1=0x50; \/\/use 2nd serial port SCON1\r\n\r\nTR1=1; \/\/start timer\r\n\r\nwhile (1) {\r\n\r\nwhile (RI1==0); \/\/monitor RI1\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\nmybyte=SBUF1; \/\/use SBUF1\r\n\r\nP2=mybyte; \/\/place value on port\r\n\r\nRI1=0;\r\n\r\n}\r\n\r\n}\r\n\r\n&nbsp;\r\n<ol start=\"3\">\r\n \t<li><strong> Summary<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify\">In this lecture, basics of serial communication is discussed. The 8051 control registers for serial communication are shown and the Serial Port programming in Embedded C for 8051 are discussed with examples.<\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n<ol start=\"4\">\r\n \t<li><strong>References<\/strong><\/li>\r\n<\/ol>\r\n<ol>\r\n \t<li>Muhammad Ali\u00a0 Mazidi,\u00a0 Janice\u00a0 Gillispie\u00a0 Mazidi,\u00a0 Rolin\u00a0 D.\u00a0 McKinlay,\u00a0 \u201cThe\u00a0 8051 Microcontroller and Embedded Systems Using Assembly and C -Second Edition\u201d, New Delhi(2000).<\/li>\r\n<\/ol>","rendered":"<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this lecture basics of serial port communication in 8051 will be discussed. The Control register in 8051 will be visited. Embedded C program for Serial port communication will be discussed in detail with examples.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong><strong>Serial Vs Parallel<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Data transferred by computer occurs in two ways. They are parallel and serial communication. Parallel Communication has 8 or more lines. It is used for transfer of data to a device that is only a short distance, while serial communication is used to transfer data over a long distance.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The data is sent one bit at a time in serial communication, whereas multiple bits are sent simultaneously in parallel communication. The difference between serial communication and parallel communication is shown in Figure 1.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-246 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-136.png\" alt=\"\" width=\"555\" height=\"203\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-136.png 555w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-136-300x110.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-136-65x24.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-136-225x82.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-136-350x128.png 350w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.1<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>Serial Communication<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The transmitter converts a byte of data into serial bits using parallel-in-serial-out shift register, while the receiver has a serial-in-parallel-out shift register to receive the serial data and pack them into a byte. For a short distance, the digital signal can be transferred on a simple wire without modulation. To transfer data over a long distance, some form of modulation may be required. For example, to transfer data on the telephone line, it must be converted from 0s and 1s to audio tones. The device which performs conversion of 0s and 1s to audio tones, and back, is called a modem, \u201cModulator\/demodulator\u201d.<\/p>\n<p>&nbsp;<\/p>\n<p>The serial communication uses two techniques for communication. They are<\/p>\n<p>\u25cf\u00a0\u00a0\u00a0\u00a0 Synchronous- transfer block of data(characters) at a time<\/p>\n<p>\u25cf\u00a0\u00a0\u00a0\u00a0 Asynchronous- transfer single byte at a time<\/p>\n<p>&nbsp;<\/p>\n<p>This communication can be done by the following hardware:<\/p>\n<p>\u25cf\u00a0\u00a0\u00a0\u00a0 USART (Universal Synchronous-Asynchronous Receiver-Transmitter)<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">\u25cf\u00a0\u00a0\u00a0\u00a0 UART (Universal Asynchronous Receiver Transmitter) The 8051 chip has a built-in UART.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Asynchronous communication is used for character-oriented transmissions, but each character is placed in between start and stop bits; this is called framing. The start bit is always one bit and the stop bit can be one or two bits. The start bit is always a 0 (low), while the stop bit(s) is 1 (high) and the LSB is sent out first. Block-oriented data transfers use the synchronous method. Data transfer rate in serial data communication is mentioned in bps (bits per second) or baud rate.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.2<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>RS232 standards<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is the most widely used serial I\/O interfacing standard for serial communication. The input and output voltage levels are not TTL compatible. The bit-value of 1 is represented as -3 to -25 V and the value0 is represented as +3 to +25 V, while -3 to +3 is undefined. To connect RS232 to a microcontroller system, it must use voltage converters such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and vice versa. MAX232 IC chips are commonly referred to as line drivers.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.3 8051 connections to RS232<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">8051 has two pins used for transferring and receiving data serially. They are TxD and RxD pins. TxD and RxD are part of the port 3 group (P3.0 and P3.1), while pin 11 (P3.1) of 8051 is assigned to TxD. The pin 10 (P3.0) of 8051 is assigned to RxD. These pins are TTL compatible. They require a line driver to make them RS232 compatible. The driver used for this is MAX232 chip.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.4 Serial Communication Registers<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>SBUF Register:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is an 8-bit register used for serial communication. To transmit a byte of data via the TxD line, it must be placed in the SBUF register. When a byte is written into SBUF, it is framed with the start and stop bits and transferred serially via the TxD line. SBUF holds the byte of data when it is received by 8051 RxD line. When the bits are received serially via RxD, 8051 deframes it by removing the stop and start bits, making a byte out of the data received, and then places it in SBUF register.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>SCON (serial control) register:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is an 8-bit register used to program start bit, stop bit, and data bits of data for framing, among other things. In this SM0 and SM1 are used to determine the mode. If (SM0,SM1) is (0,0) then it is mode 0, in this mode the serial port function as half duplex serial port with fixed baud rate.If (SM0,SM1) is (0,1) it is mode1,in this mode the serial port function as full duplex serial port with variable baud rate. If (SM0,SM1) is (1,0) then it is mode 2, in this mode the serial port function as full duplex serial port with a baud rate of either 1\/32 or 1\/64 of the oscillator frequency. If (SM0,SM1) is (1,1) then it is mode 3.The mode-3 is same as mode-2, except the baud rate.In all these modes, only mode 1 is important. When mode 1 is chosen, the following bits are compatible with the COM port of PCs. They are 8 bits of data with 1 stop bit, and 1 start bit. The mode 1 allows the baud rate to be variable and is set by Timer 1 of the 8051. For each\u00a0<span style=\"font-size: 1em;text-align: initial\">character a total of 10 bits are transferred, where the first bit is the start bit, followed by 8 bits of data, and finally 1 stop bit.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">REN is the receive enable. If REN=1, it allows 8051 to receive data on the RxD. If 8051 is to both transfer and receive data, REN must be set to 1. If REN=0, the receiver is disabled and TB8 is used for serial modes 2 and 3. The figure 2 shown below specifies the bits of the SCON register.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-247 aligncenter\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-137.png\" alt=\"\" width=\"715\" height=\"322\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-137.png 715w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-137-300x135.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-137-65x29.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-137-225x101.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-137-350x158.png 350w\" sizes=\"auto, (max-width: 715px) 100vw, 715px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.5<\/strong>\u00a0<strong>Use of Baud rate in 8051<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Baud rate in 8051 is programmable. It is done with the help of Timer 1. Timer 1 must be programmed in mode 2, that is, 8-bit, auto-reload. We must make sure that the baud rate of the 8051 system matches the baud rate of the system used for communication.<\/p>\n<p>&nbsp;<\/p>\n<p>Relationship between the crystal frequency and the baud rate in the 8051 is as follows:<\/p>\n<p>\u25aa\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8051 divides the crystal frequency by 12 to get the machine cycle frequency.<\/p>\n<p>\u25aa\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Load FD\/FA\/F4\/E8 in TH1 to get 9600\/4800\/2400\/1200 baud rate.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.6<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>Steps to send data serially in serial port communication<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The following are the steps to send the data serially in serial port communication:<\/p>\n<p>&nbsp;<\/p>\n<p>1. Set baud rate by loading TMOD register with the value 20H; this indicates timer 1 in mode 2 (8-bit auto-reload) to set baud rate.<\/p>\n<p>2. The TH1 is loaded with proper values to set baud rate for serial data transfer.<\/p>\n<p>3.\u00a0\u00a0\u00a0 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.<\/p>\n<p>4.\u00a0\u00a0\u00a0 TR1 is set to 1 to start timer 1.<\/p>\n<p>5.\u00a0\u00a0\u00a0 Transmit Interrupt(TI) is cleared by CLR TI instruction.<\/p>\n<p>6.\u00a0\u00a0\u00a0 The character byte to be transferred serially is written into SBUF register.<\/p>\n<p>7.\u00a0\u00a0\u00a0 The TI flag bit is monitored to see if the character has been transferred completely.<\/p>\n<p>8.\u00a0\u00a0\u00a0 To transfer the next byte, go to step 5.<\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>1.7<\/strong>\u00a0<strong>Importance of the TI flag:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The following steps are the importance of TI flag in 8051 serial port communication<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">\u25cf\u00a0\u00a0\u00a0\u00a0 Check the TI flag bit, we know whether or not 8051 is ready to transfer another byte.<\/p>\n<p style=\"text-align: justify\">\u25cf\u00a0\u00a0\u00a0\u00a0 TI flag bit is raised by the 8051 after transfer of data.<\/p>\n<p style=\"text-align: justify\">\u25cf\u00a0\u00a0\u00a0\u00a0 TI flag is cleared by the programmer by instructions like \u201cCLR TI\u201d.<\/p>\n<p>&nbsp;<\/p>\n<p>\u25cf\u00a0\u00a0\u00a0\u00a0 Writing a byte into SBUF before the TI flag bit is raised, may lead to loss of a portion of the byte being transferred.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.8\u00a0<\/strong>\u00a0<strong>Steps to receive data serially in serial port communication<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The following are the steps to receive the data serially in the serial port communication:<\/p>\n<p>&nbsp;<\/p>\n<p>1. Set baud rate by loading TMOD register with the value 20H; this indicates setting of timer 1 in mode 2 (8-bit auto-reload) to set baud rate.<\/p>\n<p>2. The TH1 is loaded with proper values to set baud rate.<\/p>\n<p style=\"text-align: justify\">3.\u00a0 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.<\/p>\n<p>4.\u00a0\u00a0\u00a0 TR1 is set to 1 to start timer 1.<\/p>\n<p>5.\u00a0\u00a0\u00a0 Receive Interrupt(RI) is cleared by CLR RI instruction.<\/p>\n<p>6.\u00a0\u00a0\u00a0 The RI flag bit is monitored to see if an entire character has been received yet.<\/p>\n<p>7.\u00a0\u00a0\u00a0 When RI is raised, SBUF has the byte, its contents are moved into a safe place.<\/p>\n<p>8.\u00a0\u00a0\u00a0 To receive next character, go to step 5.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.9<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>Importance of the RI flag:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The following point to the importance of RI flag in 8051 serial port communication:<\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0\u00a0\u00a0 It receives the start bit, next bit is the first bit of the character about to be received.<\/p>\n<p>2.\u00a0\u00a0\u00a0 When the last bit is received, a byte is formed and placed in the SBUF register.<\/p>\n<p>3.\u00a0\u00a0\u00a0 When the stop bit is received, it makes RI = 1 indicating that the entire character byte has been received and can be written before being overwritten.<\/p>\n<p>4.\u00a0\u00a0\u00a0 When RI=1, received byte is in the SBUF register, copy SBUF contents to a safe place.<\/p>\n<p>5.\u00a0\u00a0\u00a0 After the SBUF contents are copied, the RI flag bit must be cleared to 0.<\/p>\n<p>&nbsp;<\/p>\n<p>We will now look at programming these using Embedded C.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2.\u00a0<\/strong><strong>8051 Embedded C Programming for Serial Port Communication<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">SFR registers of 8051 are accessible directly in 8051 C compilers by using reg51.h. It has already been described in the previous modules. Example 1 shows how to program the serial port in 8051 using Embedded C. For testing operation, HyperTerminal is used for this example.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 1<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Write a C program for 8051 to transfer the letter \u201cA\u201d serially at 4800 baud continuously.<\/p>\n<\/div>\n<div>\n<p>Use 8-bit data and 1 stop bit.<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>#include &lt;reg51.h&gt;<\/p>\n<p>void main(void){<\/p>\n<p>TMOD=0x20; \/\/use Timer 1, mode 2<\/p>\n<p>TH1=0xFA; \/\/4800 baud rate<\/p>\n<p>SCON=0x50;<\/p>\n<p>TR1=1;<\/p>\n<p>while (1) {<\/p>\n<p>SBUF=\u2018A\u2019; \/\/place value in buffer<\/p>\n<p>while (TI==0);<\/p>\n<p>TI=0;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Example 2 described below gives the details about how to transfer the message serially with 9600 baud continuously.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 2<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Write an 8051 C program to transfer the message \u201cYES\u201d serially at 9600 baud, 8-bit data, 1 stop bit. Do this continuously.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>#include &lt;reg51.h&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>void SerTx(unsigned char);<\/p>\n<p>void main(void){<\/p>\n<p>TMOD=0x20; \/\/use Timer 1, mode 2<\/p>\n<p>TH1=0xFD; \/\/9600 baud rate<\/p>\n<p>SCON=0x50;<\/p>\n<p>TR1=1; \/\/start timer<\/p>\n<p>while (1) {<\/p>\n<p>SerTx(\u2018Y\u2019);<\/p>\n<p>SerTx(\u2018E\u2019);<\/p>\n<p>SerTx(\u2018S\u2019);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>void SerTx(unsigned char x){<\/p>\n<p>SBUF=x; \/\/place value in buffer<\/p>\n<p>while (TI==0); \/\/wait until transmitted<\/p>\n<p>TI=0;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Example 3 described below gives the details about how to receive the data serially and put in Port P1 with 4800 baud and 1 stop bit. Here, Timer 1 in mode 2 is used for stopping the bit while receiving the data. The received data stored in the SBUF is then written to port P1.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 3<\/strong><\/p>\n<\/div>\n<div>\n<p style=\"text-align: justify\">Program the 8051 in C to receive bytes of data serially and put them in P1. Set the baud rate at 4800; use 8-bit data, and 1 stop bit.<\/p>\n<p>&nbsp;<\/p>\n<p>#include &lt;reg51.h&gt;<\/p>\n<p>void main(void){<\/p>\n<p>unsigned char mybyte;<\/p>\n<p>TMOD=0x20; \/\/use Timer 1, mode 2<\/p>\n<p>TH1=0xFA; \/\/4800 baud rate<\/p>\n<p>SCON=0x50;<\/p>\n<p>TR1=1; \/\/start timer<\/p>\n<p>while (1) { \/\/repeat forever<\/p>\n<p>while (RI==0); \/\/wait to receive<\/p>\n<p>mybyte=SBUF; \/\/save value<\/p>\n<p>P1=mybyte; \/\/write value to port<\/p>\n<p>RI=0;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Example 4 described below gives the details about sending two messages to serial port with 28,800 and 56K baud. Here Timer 1 in mode 2 is used. The data is stored in the SBUF and then it waits to transmit to the corresponding destination.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 4<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Write an 8051 C Program to send the two messages \u201cNormal Speed\u201d and \u201cHigh Speed\u201d to the serial port. Assuming that SW is connected to pin P2.0, monitor its status and set the baud rate as follows:<\/p>\n<p>&nbsp;<\/p>\n<p>SW = 0, 28,800 baud rate<\/p>\n<p>SW = 1, 56K baud rate<\/p>\n<p>Assume that XTAL = 11.0592 MHz for both cases.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>#include &lt;reg51.h&gt;<\/p>\n<p>&nbsp;<\/p>\n<p>sbit MYSW=P2^0; \/\/input switch<\/p>\n<p>void main(void){<\/p>\n<p>unsigned char z;<\/p>\n<p>unsigned char Mess1[]=\u201cNormal Speed\u201d;<\/p>\n<p>unsigned char Mess2[]=\u201cHigh Speed\u201d;<\/p>\n<p>TMOD=0x20; \/\/use Timer 1, mode 2<\/p>\n<p>TH1=0xFF; \/\/28800 for normal<\/p>\n<p>SCON=0x50;<\/p>\n<p>TR1=1; \/\/start timer<\/p>\n<p>if(MYSW==0) {<\/p>\n<p>for (z=0;z&lt;12;z++) {<\/p>\n<p>SBUF=Mess1[z]; \/\/place value in buffer<\/p>\n<p>while(TI==0); \/\/wait for transmit<\/p>\n<p>TI=0;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>else {<\/p>\n<p>PCON=PCON|0x80; \/\/for high speed of 56K<\/p>\n<p>for (z=0;z&lt;10;z++) {<\/p>\n<p>SBUF=Mess2[z]; \/\/place value in buffer<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div>\n<p>while(TI==0); \/\/wait for transmit<\/p>\n<p>TI=0;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Example 5 described below gives the details about transferring the letter A serially with 4,800 baud continuously. Here Timer 1 in mode 2 is used to set the baud rate. The data is stored in the SBUF and new addresses for DS89C4x0 chip are declared using SFR registers using sfr keyword.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 5<\/strong><\/p>\n<p style=\"text-align: justify\">\n<p style=\"text-align: justify\">Write a C program for the DS89C4x0 to transfer the letter \u201cA\u201d serially at 4800 baud continuously. Use the second serial port with 8-bit data and 1 stop bit. (note: We can only use Timer 1 to set the baud rate).<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>#include &lt;reg51.h&gt;<\/p>\n<p>sfr SBUF1=0xC1;<\/p>\n<p>sfr SCON1=0xC0;<\/p>\n<p>sbit TI1=0xC1;<\/p>\n<p>void main(void){<\/p>\n<p>TMOD=0x20; \/\/use Timer 1, mode 2<\/p>\n<p>TH1=0xFA; \/\/4800 baud rate<\/p>\n<p>SCON1=0x50; \/\/use 2nd serial port SCON1<\/p>\n<p>TR1=1; \/\/start timer<\/p>\n<p>while (1) {<\/p>\n<p>SBUF1=\u2018A\u2019; \/\/use 2nd serial port SBUF1<\/p>\n<p>while (TI1==0); \/\/wait for transmit<\/p>\n<p>TI1=0;<\/p>\n<p>}}<\/p>\n<p>&nbsp;<\/p>\n<p>Example 6 described below gives the details about receiving the data serially with 9,600 bauds via second serial port. Here Timer 1 in mode 2 is used to set the baud rate.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 6<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Program the DS89C4x0 in C to receive bytes of data serially via the second serial port and put them in P1. Set the baud rate at 9600, 8-bit data and 1 stop bit. Use Timer 1 for baud rate generation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>#include &lt;reg51.h&gt;<\/p>\n<p>sfr SBUF1=0xC1;<\/p>\n<p>sfr SCON1=0xC0;<\/p>\n<p>sbit RI1=0xC0;<\/p>\n<p>void main(void){<\/p>\n<p>unsigned char mybyte;<\/p>\n<p>TMOD=0x20; \/\/use Timer 1, mode 2<\/p>\n<p>TH1=0xFD; \/\/9600 baud rate<\/p>\n<p>SCON1=0x50; \/\/use 2nd serial port SCON1<\/p>\n<p>TR1=1; \/\/start timer<\/p>\n<p>while (1) {<\/p>\n<p>while (RI1==0); \/\/monitor RI1<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>mybyte=SBUF1; \/\/use SBUF1<\/p>\n<p>P2=mybyte; \/\/place value on port<\/p>\n<p>RI1=0;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<ol start=\"3\">\n<li><strong> Summary<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify\">In this lecture, basics of serial communication is discussed. The 8051 control registers for serial communication are shown and the Serial Port programming in Embedded C for 8051 are discussed with examples.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<ol start=\"4\">\n<li><strong>References<\/strong><\/li>\n<\/ol>\n<ol>\n<li>Muhammad Ali\u00a0 Mazidi,\u00a0 Janice\u00a0 Gillispie\u00a0 Mazidi,\u00a0 Rolin\u00a0 D.\u00a0 McKinlay,\u00a0 \u201cThe\u00a0 8051 Microcontroller and Embedded Systems Using Assembly and C -Second Edition\u201d, New Delhi(2000).<\/li>\n<\/ol>\n","protected":false},"author":2,"menu_order":20,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-k-vani"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-243","chapter","type-chapter","status-publish","hentry","contributor-dr-k-vani"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":3,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/243\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/243\/revisions\/248"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/243\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapter-type?post=243"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/contributor?post=243"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/license?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}