92
CHAPTER 10 8051 SERIAL COMMUNICATION 1

microcontroller basics and programming

Embed Size (px)

DESCRIPTION

basics of microcontroller and programming (8051)

Citation preview

  • CHAPTER 10 8051 SERIAL COMMUNICATION*

  • SECTIONS10.1 Basics of serial communication10.2 8051 connection to RS23210.3 8051 serial communication programming*

  • SECTION 10.1BASICS OF SERIAL COMMUNICATION*

  • 8051 AND PCThe 8051 module connects to PC by using RS232.RS232 is a protocol which supports half-duplex, synchronous/asynchronous, serial communication.We discuss these terms in following sections.*

  • SIMPLEX VS. DUPLEX TRANSMISSIONSimplex transmission: the data can sent in one direction.Example: the computer only sends data to the printer.

    Duplex transmission: the data can be transmitted and receive*TransmitterReceiverTransmitterReceiverReceiverTransmitter

  • HALF VS. FULL DUPLEXHalf duplex: if the data is transmitted one way at a time.

    Full duplex: if the data can go both ways at the same time.Two wire conductors for the data lines.*TransmitterReceiverReceiverTransmitterTransmitterReceiverReceiverTransmitter

  • FIGURE 10-2. SIMPLEX, HALF-, AND FULL-DUPLEX TRANSFERS*Half DuplexFull DuplexTransmitterReceiverTransmitterReceiverReceiverTransmitterReceiverTransmitter

  • PARALLEL VS. SERIALComputers transfer data in two ways:Paralleldata is sent a byte or more a time (fast)Only short distance between two systemsThe 8-bit data path is expensiveExample: printer, hard disksSerialThe data is sent one bit at a time (slow)Long distance (rarely distortion)cheapThe data can be transferred on the telephone line (by using modem.)*

  • FIGURE 10-1. SERIAL VERSUS PARALLEL DATA TRANSFER (1/2)*

  • FIGURE 10-1. SERIAL VERSUS PARALLEL DATA TRANSFER (2/2)*SenderReceiverSenderReceiverSerial TransferParallel TransferD0-D7D0Other control linesOther control lines

  • SERIAL COMMUNICATIONHow to transfer data?Sender:The byte of data must be converted to serial bits using a parallel-in-serial-out shift register.The bit is transmitted over a single data line.ReceiverThe receiver must be a serial-in-parallel-out shift register to receive the serial data and pack them into a byte.*11101000001011Aregister8-bit characterregister81parallel-in serial-outserial-in parallel-out

  • ASYNCHRONOUS VS. SYNCHRONOUSSerial communication uses two methods:In synchronous communication, data is sent in blocks of bytes.

    In asynchronous communication, data is sent in bytes.*bytebytebytebyte 01011111preamble 01010101senderreceiverbytesenderreceiverstart bitstop bitbytebyte

  • UART & USARTIt is possible to write software to use both methods, but the programs can be tedious and long.Special IC chips are made for serial communication:USART (universal synchronous-asynchronous receiver-transmitter)UART (universal asynchronous receiver-transmitter)The 8051 chip has a built-in UART.*

  • 8051 SERIAL COMMUNICATIONThe 8051 has serial communication capability built into it.Half-duplexAsynchronous mode only.How to detect that a character is sent via the line in the asynchronous mode?Answer: Data framing!

    *

  • FRAMING (1/3)Each character is placed in between start and stop bits. This is called framing.Figure 10-3. Framing ASCII A (41H)*stopbitstartbitmark00000011D7D0goes out lastgoes out lastTime (D0 first)mark

  • FRAMING (2/3)The LSB is sent out first.The start bit is 0 (low) and always one bit.The stop bits is 1 (high).The stop bit can be one (if 8 bits used in ASCII) or two bits (if 7 bits used in ASCII).In asynchronous serial communication, peripheral chips and modems can be programmed for data that is 7 or 8 bits.When there is no transfer, the signal is 1 (high), which is referred to as mask.*

  • FRAMING (3/3)We have a total of 10 bits for each character:8-bits for the ASCII code2-bits for the start and stop bits25% overheadIn some systems in order to maintain data integrity, the parity bit is included in the data frame.In an odd-parity bit system the total number of bits, including the parity bit, is odd.UART chips allow programming of the parity bit for odd-, even-, and no-parity options.*

  • DATA TRANSFER RATE (1/2)How fast is the data transferred?Three methods to describe the speed:Baud rate is defined as the number of signal changes per second.The rate of data transfer is stated in Hz (used in modem).Date rate is defined as the number of bits transferred per second.Each signal has several voltage levels.The rate of data transfer is stated in bps (bits per second).Effective data rate is defined as the number of actual data bits transferred per second.Redundant bits must be removed*

  • DATA TRANSFER RATE (2/2)The data transfer rate depends on communication ports incorporated into that system.Ex: 100-9600 bps in the early IBM PC/XT Ex: 56K bps in Pentium-based PC The baud rate is generally limited to 100kHz.*

  • EXAMPLE OF DATA TRANSFER RATE (1/2)Data is sent in the following asynchronous mode:2400 baud rateeach signal has 4 voltage levels (-5V, -3V, 3V, 5V) one start bit, 8-bit data, 2 stop bits*

  • EXAMPLE OF DATA TRANSFER RATE (2/2)2400 baud = 2400 signals per second =2400 Hz4 voltage level: Log24=22 bits is sent in every signal changeData rate = 2 * 2400 Hz = 4800 bpsEffective ratio = 8 / (1+8+2) =8/11Effective data rate = data rate * effective ratio = 4800 * 8 /11=3490.9*

  • RS232 STANDARDRS232 is an interfacing standard which is set by the Electronics Industries Association (EIA) in 1960.RS232 is the most widely used serial I/O interfacing standard.RS232A (1963), RS232B (1965) and RS232C (1969), now is RS232EDefine the voltage level, pin functionality, baud rate, signal meaning, communication distance.*

  • RS232 VOLTAGE LEVELThe input and output voltage of RS232 is not of the TTL compatible.RS232 is older than TTL.We must use voltage converter (also referred to as line driver) such as MAX232 to convert the TTL logic levels to the RS232 voltage level, and vice versa.MAX232, TSC232, ICL232*

  • MAX232MAX232 IC chips are commonly referred to as line drivers.*RS232 voltage levelTTL voltage levelTTL voltage level

  • RS232 PINSFigure 10-4 shows the RS232 connector DB-25.Table 10-1 shows the pins and their labels for the RS232 cable.DB-25P : plug connector (male)DB-25S: socket connector (female)Figure 10-5 shows DB9 connector and Table 10-2 shows the signals.IBM version for PC.All the RS 232 pin function definitions of Tables 10-1 and 10-2 are from the DTE point of view.*

  • FIGURE 10-4. RS232 CONNECTOR DB-25*

  • TABLE 10-1: RS232 PINS (DB-25) FOR DTE (1/2)*

    PinDescription1Protective ground2Transmitted data (TxD)3Received data (RxD)4Request to send (RTS)5Clear to send (CTS)6Data set ready (DSR)7Signal ground (GND)8Data carrier detect (DCD)9/10Reserved for data testing11Unassigned12Secondary data carrier detect13Secondary clear to send

  • TABLE 10-1: RS232 PINS (DB-25) FOR DTE (2/2)*

    PinDescription14Secondary transmitted data15Transmit signal element timing16Secondary received data17Receive signal element timing18Unassigned19Secondary request to sent20Data terminal ready (DTR)21Signal quality detector22Ring indicator23Data signal rate select24Transmit signal element timing25Unassigned

  • FIGURE 10-5. DB-9 9-PIN CONNECTOR*

  • TABLE 10-2: IBM PC DB-9 SIGNALS FOR DTE*

    PinDescription1Data carrier detect (DCD)2Received data (RxD)3Transmitted data (TxD)4Data terminal ready (DTR)5Signal ground (GND)6Data set ready (DSR)7Request to send (RTS)8Clear to send (CTS)9Ring indicator (RI)

  • RS232 HANDSHAKING SIGNALSMany of the pins of the RS232 connector are used for handshaking signals.DTR (data terminal ready)DSR (data set ready)RTS (request to send)CTS (clear to send)RTS and CTS are hardware control flow signals.DCD (carrier detect, or data carrier detect)RI (ring indicator)They are not supported by the 8051 UART chips.*

  • COMMUNICATION FLOW (1/2)Telephone is ringingConnection between two modems is setPC is readymodem is readyPC wants to sent datamodem is ready to receivetransmit data*PC (DTE)modem (DCE)DTRDSRRTSCTSTxD, RxDRIDCD

  • COMMUNICATION FLOW (2/2)While signals DTR and DSR are used by the PC and modem, respectively, to indicate that they are alive and well.TRS and CTS control the flow of data.When the PC wants to send data, it asserts RTS.If the modem is ready (has room) to accept the data, it sends back CTS.If, for lack of room, the modem does not activate CTS, and PC will deassert DTR and try again.*

  • DTE AND DCECommunication Equipments are classified asDTE (data terminal equipment)Terminals and computers that send and receive dataDCE (data communication equipment)Communication equipment (only for transfer data)Ex: modem*TxDRxDDTERxDTxDDCEGNDPC Com1modemGNDTxDRxDDTERxDTxDDCEGNDPC Com1modemGNDTelephone LineDTE viewDCE view

  • IBM PC/COMPATIBLE COM PORTSIBM PC has 2 COM ports. Both COM ports have RS232-type connectors.For mouse, modemWe can connect the 8051 serial port to the COM port of a PC for serial communication experiments.*DTE viewDTE view

  • NULL MODEM CONNECTIONThe simplest connection between a PC and microcontroller requires a minimum of three pins, TxD, RxD, and GND.Figure 10-6 shows null modem connection*PC Com18051-based boardPC Com1PC Com1

  • RS422 & RS485By using RS232, the limit distance between two PCs is about 15m. It works well even the distance=30m.If you want to transfer data with long distance (ex: 300m), you can use RS422 or RS485.*

  • SECTION 10.28051 CONNECTION TO RS232*

  • TXD AND RXD PINS IN THE 8051In 8051, the data is received from or transmitted toRxD: received data (Pin 10, P3.0)TxD: transmitted data (Pin 11, P3.1)TxD and RxD of the 8051 are TTL compatible.The 8051 requires a line driver to make them RS232 compatible.One such line driver is the MAX232 chip.*

  • FIGURE 4-1. 8051 PIN DIAGRAM*PDIP/Cerdip input eventdata transferstart/stop

  • MAX232 (1/2)MAX232 chip converts from RS232 voltage levels to TTL voltage levels, and vice versa.MAX232 uses a +5V power source which is the same as the source voltage for the 8051.*

  • MAX232 (2/2)MAX232 has two sets of line drivers.Figure 10.7 shows the inside of MAX232.MAX232 requires four capacitors ranging from 1 to 22 mF. The most widely used value for these capacitors is 22mF.MAX233 performs the same job as the MAX232 but eliminates the need for capacitors.Note that MAX233 and MAX232 are not pin compatible.Figure 10.8 (a) shows the inside of MAX233Figure 10.8 (b) shows the connection to the 8051*

  • FIGURE 10-7 (A): INSIDE MAX232*

  • FIGURE 10-7: (B) MAX232S CONNECTION TO THE 8051 (NULL MODEM)*RS232-compatibleTTL-compatible

  • FIGURE 10-8: (A) INSIDE MAX233*

  • FIGURE 10-8: (B) MAX233S CONNECTION TO THE 8051 (NULL MODEM)*RS232-compatibleTTL-compatible

  • SECTION 10.38051 SERIAL COMMUNICATION PROGRAMMING*

  • PC BAUD RATESPC supports several baud rates.You can use netterm, terminal.exe, stty, ptty to send/receive data.Hyperterminal supports baud rates much higher than the ones list in the Table.*

    110 bps 150 300 600 1200 2400 4800 9600 (default) 19200Note: Baud rates supported by 486/Pentium IBM PC BIOS.

  • BAUD RATES IN THE 8051 (1/2)The 8051 transfers and receives data serially at many different baud rates by using UART.UART divides the machine cycle frequency by 32 and sends it to Timer 1 to set the baud rate. Signal change for each roll over of timer 1*

  • BAUD RATES IN THE 8051Timer 1, mode 2 (8-bit, auto-reload)Define TH1 to set the baud rate.XTAL = 11.0592 MHzThe system frequency = 11.0592 MHz / 12 = 921.6 kHzTimer 1 has 921.6 kHz/ 32 = 28,800 Hz as source.TH1=FDH means that UART sends a bit every 3 timer source.Baud rate = 28,800/3= 9,600 Hz*

  • EXAMPLE 10-1 (1)With XTAL = 11.0592 MHz, find the TH1 value needed to have thefollowing baud rates. (a) 9600 (b) 2400 (c) 1200Solution:With XTAL = 11.0592 MHz, we have:The frequency of system clock = 11.0592 MHz / 12 = 921.6 kHzThe frequency sent to timer 1 = 921.6 kHz/ 32 = 28,800 Hz (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/12th of the crystal frequency by 32 is thedefault value upon activation of the 8051 RESET pin. *

  • TABLE 10-4: TIMER 1 TH1 REGISTER VALUES FOR VARIOUS BAUD RATES*

    Baud RateTH1 (Decimal)TH1 (Hex)9600-3FD4800-6FA2400-12F41200-24E8Note: XTAL = 11.0592 MHz.

  • REGISTERS USED IN SERIAL TRANSFER CIRCUITSUBF (Serial data buffer)SCON (Serial control register)PCON (Power control register)You can see Appendix H (pages 416-417) for details.PC has several registers to control COM1, COM2.*

  • SBUF REGISTERSerial data register: SBUFMOV SBUF,#A ;put char A to transmitMOV SBUF,A ;send data from AMOV A,SUBF ;receive and copy to AAn 8-bit registerSet the usage mode for two timers For a byte of data to be transferred via the TxD line, it must be placed in the SBUF.SBUF holds the byte of data when it is received by the 8051;s RxD line.Not bit-addressable *

  • SCON REGISTERSerial control register: SCONSM0, SM1 Serial port mode specifierREN (Receive enable) set/cleared by software to enable/disable reception.TI Transmit interrupt flag.RI Receive interrupt flag.SM2 = TB8 = TB8 =0 (not widely used) *(LSB)(MSB)* SCON is bit-addressable.

  • SM0, SM1SM1 and SM0 determine the framing of data.SCON.6 (SM1) and SCON.7 (SM0)Only mode 1 is compatible with COM port of IBM PC. See Appendix A.3.

    SM1 SM0 Mode Operating Mode Baud Rate 0 0 0 Shift register Fosc./120 1 1 8-bit UART Variable by timer11 0 2 9-bit UART Fosc./64 or Fosc./32 1 1 3 9-bit UART Variable*

  • SM2SCON.5SM2 enables the multiprocessor communication for mode 2 & 3.We make it 0 since we are not using the 8051 in a multiprocessor environment.SM2=0 : Single processor environmentSM2=1 : multiprocessor environment

    *

  • REN (RECEIVE ENABLE)SCON.4Set/cleared by software to enable/disable reception.REN=1It enable the 8051 to receive data on the RxD pin of the 8051.If we want the 8051 to both transfer and receive data, REN must be set to 1.SETB SCON.4REN=0The receiver is disabled. The 8051 can not receive data.CLR SCON.4*

  • TB8 (TRANSFER BIT 8)SCON.3TB8 is used for serial modes 2 and 3.The 9th bit that will be transmitted in mode 2 & 3.Set/Cleared by software.*

  • RB8 (RECEIVE BIT 8)SCON.2In serial mode 1, RB8 gets a copy of the stop bit when an 8-bit data is received.*

  • TI (TRANSMIT INTERRUPT FLAG)SCON.1When the 8051 finishes the transfer of the 8-bit character, it raises the TI flag.TI is raised by hardware at the beginning of the stop bit in mode 1. Must be cleared by software.*

  • RI (RECEIVE INTERRUPT)SCON.0Receive interrupt flag. Set by hardware halfway through the stop bit time in mode 1. Must be cleared by software.When the 8051 receives data serially via RxD, it gets rid of the start and stop bits and place the byte in the SBUF register.Then 8051 rises RI to indicate that a byte.RI is raised at the beginning of the stop bit.*

  • FIGURE 10-9. SCON SERIAL PORT CONTROL REGISTER (BIT ADDRESSABLE)*

    SM0SCON.7Serial port mode specifierSM1SCON.6Serial port mode specifierSM2SCON.5Used for multiprocessor communication. (Make it 0)RENSCON.4Set/cleared by software to enable/disable reception.TB8SCON.3Not widely used.RB8SCON.2Not widely used.TISCON.1Transmit interrupt flag. Set by hardware at the beginning of the stop bit in mode 1. Must be cleared by software.RISCON.0Receive interrupt flag. Set by hardware halfway through the stop bit time in mode 1. Must be cleared by software.Note: Make SM2, TB8, and RB8 = 0.

  • TRANSFER DATA WITH THE TI FLAG (1/2)The following sequence is the steps that the 8051 goes through in transmitting a character via TxD:The byte character to be transmitted is written into the SBUF register.It transfers the start bit.The 8-bit character is transferred one bit at a time.The stop bit is transferred. *SBUFTxDbit by bit8-bit charUARTTI

  • TRANSFER DATA WITH THE TI FLAG (2/2)Sequence continuous:During the transfer of the stop bit, the 8051 raises the TI flag, indicating that the last character was transmitted and it is ready to transfer the next character.By monitoring the TI flag, we know whether or not the 8051 is ready to transfer another byte.We will not overloading the SBUF register. If we write another byte into the SBUF before TI is raised, the untransmitted portion of the previous byte will be lost.We can use interrupt to transfer data in Chapter 11.After SBUF is loaded with a new byte, the TI flag bit must be cleared by the programmer.*

  • PROGRAMMING THE 8051 TO TRANSFER DATA SERIALLY (1/2)Use the timer 1 in mode 2 MOV TMOD,#20HSet the value TH1 to chose baud rate. Look at the Table 10-4.MOV TH1,#FDH ;Baud rate = 9600bpsSet SCON register in mode 1.MOV SCON,#50HStart the timer.SETB TR1*

  • PROGRAMMING THE 8051 TO TRANSFER DATA SERIALLY (2/2)Clear TI flag.CLR TIThe character byte to be transferred serially is written into the SBUF register.MOV SBUF,#AKeep monitoring the Transmit Interrupt (TI) to see if it is raised.HERE: JNB TI, HERE To transfer the next character, go to Step 5.*TI=0 transfer dataraise when sending the stop bit

  • EXAMPLE 10-2Write a program for the 8051 to transfer letter A serially at 4800baud, continuously.Solution: MOV TMOD,#20H ;timer 1, mode 2 MOV TH1,#-6 ;4800 baud rate MOV SCON,#50H ;8-bit,1 stop,REN enabled SETB TR1 ;start timer 1AGAIN: MOV SBUF,#A ;letter A to be transferredHERE: JNB TI,HERE ;wait for the last bit CLR TI ;clear TI for next char SJMP AGAIN ;keep sending A*

  • EXAMPLE 10-3 (1/2)Write a program to transfer the message YES serially at 9600baud, 8-bit data, 1 stop bit. Do this continuously.Solution: MOV TMOD,#20H ;timer 1, mode 2 MOV TH1,#-3 ;9600 baud MOV SCON,#50H SETB TR1 AGAIN:MOV A,#Y ;transfer Y ACALL TRANS MOV A,#E ;transfer E ACALL TRANS MOV A,#S ;transfer S ACALL TRANS SJMP AGAIN ;keep doing it*

  • EXAMPLE 10-3 (2/2);serial data transfer subroutineTRANS:MOV SBUF,A ;load SBUFHERE: JNB TI,HERE ;wait for last bit to transfer CLR TI ;get ready for next byte RET*

  • RECEIVE DATA WITH THE RI FLAG (1/2)The following sequence is the steps that the 8051 goes through in receiving a character via RxD:8051 receives the start bit indicating that the next bit is the first bit of the character to be received.The 8-bit character is received one bit at a time.When the last bit is received, a byte is formed and placed in SBUF.*SBUFRxDbit by bit8-bit characterUARTRI

  • RECEIVE DATA WITH THE TI FLAG (2/2)Sequence continuous:The stop bit is received. During receiving the stop bit, the 8051 make RI=1, indicating that an entire character was been received and must be picked up before it gets overwritten by an incoming character.By monitoring the RI flag, we know whether or not the 8051 has received a character byte.If we fail to copy SBUF into a safe place, we risk the loss of the received byte. We can use interrupt to transfer data in Chapter 11.After SBUF is copied into a safe place, the RI flag bit must be cleared by the programmer.*

  • PROGRAMMING THE 8051 TO RECEIVE DATA SERIALLY (1/2)Use the timer 1 in mode 2 MOV TMOD,#20HSet the value TH1 to chose baud rate. Look at the Table 10-4.MOV TH1,#FDH ;Baud rate = 28800bpsSet SCON register in mode 1.MOV SCON,#50HStart the timer.SETB TR1*

  • PROGRAMMING THE 8051 TO RECEIVE DATA SERIALLY (2/2)Clear RI flag.CLR RIKeep monitoring the Receive Interrupt (RI) to see if it is raised.HERE: JNB RI, HERE When RI is raised, SBUF has the whole byte. Move the content of SBUF to a safe place.MOV A,SBUFTo receive the next character, go to Step 5.*RI=0 receive dataraise when getting the stop bit

  • EXAMPLE 10-4Program the 8051 to receive bytes of data serially, and put them inP1. Set the baud rate at 4800, 8-bit data, and 1 stop bit.Solution: MOV TMOD,#20H ;timer1, mode 2 (auto reload) MOV TH1,#-6 ;4800 baud MOV SCON,#50H ;8-bit, 1 stop, REN enabled SETB TR1 ;start timer 1HERE: JNB RI,HERE ;wait for char to come in MOV A,SBUF ;save incoming byte in A MOV P1,A ;send to port 1 CLR RI ;get ready to receive next byte SJMP HERE ;keep getting data*

  • EXAMPLE 10-5 (1/4)Assume that the 8051 serial port is connected to the COM port of the IBM PC, and on the PC we are using the terminal.exe program to send and receive data serially.P1 and P2 of the 8051 are connected to LEDs and switches, respectively. Write an 8051 program to (a) send to the PC the message We Are Ready, (b) receive any data sent by the PC and put it on LEDs connected to P1, and (c) get data on switches connected to P2 and send it to the PC serially. The program should perform part (a) once, but parts (b) and (c) continuously. Use the 4800 baud rate.*

  • EXAMPLE 10-5 (2/4)

    Solution: ORG 0 MOV P2,#0FFH ;make P2 an input port MOV TMOD,#20H MOV TH1,#0FAH ;4800 baud rate MOV SCON,#50H SETB TR1 ;start timer 1 MOV DPTR,#MYDATA ;load pointer for message*

  • EXAMPLE 10-5 (3/4) MOV DPTR,#MYDATA ;load pointer for messageH_1: CLR A MOVC A,@A+DPTR ;get the character JZ B_1 ;if last character get out ACALL SEND INC DPTR SJMP H_1 ;next characterB_1: MOV A,P2 ;read data on P2 ACALL SEND ;transfer it serially ACALL RECV ;get the serial data MOV P1,A ;display it on LEDs SJMP B_1 ;stay in loop indefinitely*(a)(c)(b)

  • EXAMPLE 10-5 (4/4);-----------serial data transfer. ACC has the dataSEND: MOV SBUF,A ;load the dataH_2: JNB TI,H_2 ;stay here until last bit gone CLR TI ;get ready for next char RET ;-------------- Receive data serially in ACCRECV: JNB RI,RECV ;wait here for char MOV A,SBUF ;save it in ACC CLR RI ;get ready for next char RET ;---------------The message to sendMYDATA:DB We Are Ready,0 END*

  • DOUBLING THE BAUD RATE IN THE 8051There are two ways to increase the baud rate of data transfer in the 8051:To use a higher frequency crystal.It is not feasible in many situations since the system crystal is fixed.Many new crystal may not be compatible with the IBM PC serial COM ports baud rate.To change a bit in the PCON register.This is a software way by setting SMOD=1.*

  • PCON REGISTERSMOD Double baud rate. If Timer 1 is used to generate baud and SMOD=1, the baud rate is doubled when the Serial Port is used in modes 1,2,3GF1,GF0 General purpose flag bit.PD Power down bit. Setting this bit activates Power Down operation in the 80C51BH. (precedence)IDL Idle Mode bit. Setting this bit activates Idle Mode operation in the 80C51BH. *(LSB)(MSB)* PCON is not bit-addressable. See Appendix H. p410

  • SMOD FLAG OF THE PCON REGISTERPower control register: PCONMOV A, PCON SETB ACC.7 MOV PCON,A ;we dont want to modify other bitsAn 8-bit registerNot bit-addressableSCOM=0: defaultSCOM=1: double the baud rate See Table 10-5*

  • TABLE 10-5: BAUD RATE COMPARISON FOR SMOD = 0 AND SMOD =1*

    TH1 (Decimal)(Hex)SMOD = 0SMOD = 1-3FD9,60019,200-6FA4,8009,600-12F42,4004,800-24E81,2002,400Note: XTAL = 11.0592 MHz.

  • BAUD RATES FOR SMOD=0When SMOD=0, the 8051 divides 1/12 of the crystal frequency by 32, and uses that frequency for timer 1 to set the baud rate.XTAL = 11.0592 MHzThe system frequency = 11.0592 MHz / 12 = 921.6 kHzTimer 1 has 921.6 kHz/ 32 = 28,800 Hz as source.TH1=256 - Crystal frequency/(12*32*Baud rate)Default on resetSee Appendix A, page 363*

  • BAUD RATES FOR SMOD=1When SMOD=0, the 8051 divides 1/12 of the crystal frequency by 16, and uses that frequency for timer 1 to set the baud rate.XTAL = 11.0592 MHzThe system frequency = 11.0592 MHz / 12 = 921.6 kHzTimer 1 has 921.6 kHz/ 16 = 57,600 Hz as source.TH1=256 - Crystal frequency/(12*16*Baud rate)*

  • EXAMPLE 10-6 (1/2)Assuming that XTAL = 11.0592 MHz for the following program,state (a) what this program does, (b) compute the frequency used bytimer 1 to set the baud rate, and (c) find the baud rate of the datatransfer.Solution:(a) This program transfers ASCII letter B (01000010 binary) continuously.(b) and (c) With XTAL = 11.0592 MHz and SMOD = 1 11.0592 / 12 = 921.6 kHz machine cycle frequency.921.6 /16 = 57,600 Hz frequency used by timer 1 to set the baud rate.57,600 / 3 = 19,200, the baud rate.*

  • EXAMPLE 10-6 (2/2) MOV A,PCON SETB ACC.7 MOV PCON,A ;SMOD=1, double baud rate MOV TMOD,#20H ;Timer 1, mode 2,auto reload MOV TH1,#-3 ;19200 baud rate MOV SCON,#50H ;8-bit data,1 stop bit, RI enabled SETB TR1 ;start Timer 1 MOV A,#B ;transfer letter BA_1:CLR TI ;make sure TI=0 MOV SBUF,A ;transfer itH_1:JNB TI H_1 ;check TI SJMP A_1 ;do again*

  • EXAMPLE 10-7Find the TH1 value (in both decimal and hex) to set the baud rate to each of the following: (a) 9600 Hz (b) 4800 Hz if SMOD =1 Assume that XTAL = 11.0592 MHz.Solution:With XTAL = 11.0592 and SMOD = 1,11.0592 / 12 = 921.6 kHz machine cycle frequency.921.6 /16 = 57,600 Hz frequency used by the timer 1(a) 57,600 / 9600 = 6 TH1 = -6 or TH1 = FAH.(b) 57,600 / 4800 = 12 TH1 = -12 or TH1 = F4H.*

  • EXAMPLE 10-8Find the baud rate if TH1 = -2, SMOD = 1, and XTAL = 11.0592MHz. Is this baud rate supported by IBM/compatible PCs?Solution:With XTAL = 11.0592 and SMOD = 1, we have timer 1 frequency= 57,600 Hz. The baud rate is 57,600 / 2 = 28,800. This baud rate isnot supported by the BIOS of the PC; however, the PC can beprogrammed to do data transfer at such a speed. The software ofmany modems can do this. Also, Hyperterminal in Windows 95(and higher) supports this and other baud rates.*

  • YOU ARE ABLE TO (1/2)Contract and compare serial versus parallel communicationList the advantages of serial communication over parallelExplain serial communication protocolContrast synchronous versus asynchronous communicationContrast half- versus full-duplex transmissionExplain the process of data framing*

  • YOU ARE ABLE TO (2/2)Describe data transfer rate and bps rateDefine the RS232 standardExplain the use of the MAX232 and MAX232 chipsInterface the 8051 with an RS232 connectorDiscuss the baud rate of the 8051Describe serial communication features of the 8051Program the 8051 for serial data communication*

  • HOMEWORKChapter 10 Problems3,8,15,36,38,39,47*