Electronic Circuits - Electronic Tutorials - Electronic Hobby Projects - A Complete Electronic Resource Centre

MICROCONTROLLER TUTORIALS - 8051

Videos

Products

Sitemap

Circuits

Tutorials

8051

Introduction

Chapter 1
Types of Memory

Chapter 2
Special Function Registers

Chapter 3
Basic Registers

Chapter 4
Addressing Modes

Chapter 5
Program Flow

Chapter 6
Low Level Information

Chapter 7
Timers

Chapter 8
Serial Port Operations

Chapter 9
Interrupts

Additional Features in 8052

8052 Instruction Set

8051 Microcontroller
Serial Interrupts

Author : Craig Steiner

Source : 8052.com

Serial Interrupts

Serial Interrupts are slightly different than the rest of the interrupts. This is due to the fact that there are two interrupt flags: RI and TI. If either flag is set, a serial interrupt is triggered. As you will recall from the section on the serial port, the RI bit is set when a byte is received by the serial port and the TI bit is set when a byte has been sent.

This means that when your serial interrupt is executed, it may have been triggered because the RI flag was set or because the TI flag was set--or because both flags were set. Thus, your routine must check the status of these flags to determine what action is appropriate. Also, since the 8051 does not automatically clear the RI and TI flags you must clear these bits in your interrupt handler.

A brief code example is in order:

INT_SERIAL:

JNB RI,CHECK_TI

;If the RI flag is not set, we jump to check TI

 

MOV A,SBUF

;If we got to this line, it’s because the RI bit *was* set

 

CLR RI

;Clear the RI bit after we’ve processed it

CHECK_TI:

JNB TI,EXIT_INT

;If the TI flag is not set, we jump to the exit point

 

CLR TI

;Clear the TI bit before we send another character

 

MOV SBUF,#’A’

;Send another character to the serial port

EXIT_INT:

RETI

 

As you can see, our code checks the status of both interrupts flags. If both flags were set, both sections of code will be executed. Also note that each section of code clears its corresponding interrupt flag. If you forget to clear the interrupt bits, the serial interrupt will be executed over and over until you clear the bit. Thus it is very important that you always clear the interrupt flags in a serial interrupt.


<<< Click here to come back on (8051 - Interrupts)

<<<<  Back to 8051 / 52  Microcontroller Tutorial