Serial Interrupt Programming In 8051 Microcontroller

In this section we discuss the serial communication registers of the 8051 and show how to program them to transfer and receive data serially. Since IBM PC/compatible computers are so widely used to communicate with 8051-based systems, we will emphasize serial communications of the 8051 with the COM port of the PC. To allow data transfer between the PC and an 8051 system without any error, we must make sure that the baud rate of the 8051 system matches the baud rate of the PC’s COM port. Some of the baud rates supported by PC BIOS are listed in Table 10-3. You can examine these baud rates by going to the Windows Hyper Terminal program and clicking on the Communication Settings option. The HyperTerminal program comes with Windows.

Serial Interrupt Programming In 8051 Microcontroller

2.8 8051 Microcontroller Interrupts. That can interrupt regular program execution. Each interrupt can be enabled. Serial interrupt: 0. SECTION 11.4: PROGRAMMING THE SERIAL COMMUNICATION INTERRUPT In Chapter 10 we studied the serial communication of the 8051. 8051 Hardware Interrupts like Timer, External, Multiple, Serial Interrupt Programming in 8051 Microcontroller. Tutorial includes definition of Interrupts, an overview.

HyperTerminal supports baud rates much higher than the ones listed in Table 10-3. As discussed in previous chapters, the 8051 divides the crystal frequency by 12 to get the machine cycle frequency. In the case of XTAL = 11.0592 MHz, the machine cycle frequency is 921.6 kHz (11.0592 MHz / 12 = 921.6 kHz). The 8051 ‘s serial communication UART circuitry divides the machine cycle frequency of 921.6 kHz by 32 once more before it is used by Timer 1 to set the baud rate. Therefore, 921.6 kHz divided by 32 gives 28,800 Hz.

This is the number we will use throughout this section to find the Timer 1 value to set the baud rate. When Timer 1 is used to set the baud rate it must be programmed in mode 2, that is 8-bit, auto-reload. To get baud rates compatible with the PC, we must load TH1 with the values shown in Table 10-4. Socks Escort. Example 10-1 shows how to verify the data in Table 10-4. Verschil Vista En Xp.

Note: XTAL = 11.0592 MHz. Of the 4 serial modes, only mode I is of interest to us. Further explanation for the other three modes is in Appendix A.2. They are rarely used today.

In the SCON register, when serial mode 1 is chosen, the data framing is 8 bits, 1 stop bit, and 1 start bit, which makes it compatible with the COM port of IBM/compatible PCs. More importantly, serial mode 1 allows the baud rate to be variable and is set by Timer 1 of the 8051. In serial mode 1, for each 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. From the above discussion we conclude that by checking the TI flag bit, we know whether or not the 8051 is ready to transfer another byte. More importantly, it must be noted that the TI flag bit is raised by the 8051 itself when it finishes the transfer of data, whereas it must be cleared by the programmer with an instruction such as “CLR TI”. It also must be noted that if we write a byte into SBUF before the TI flag bit is raised, we risk the loss of a portion of the byte being transferred.

The TI flag bit can be checked by the instruction “JNB TI,...” or we can use an interrupt, as we will see in Chapter 11. In Chapter 11 we will show how to use interrupts to transfer data serially, and avoid tying down the microcontroller with instructions such as “JNB TI, xx”. Assume that the 8051 serial port is connected to the COM port of the IBM PC, and on the PC we are using the HyperTerminal program to send and receive data serially. PI 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 PI, 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.