 Hello everyone, myself Vipul Kondekar, in this video we will be talking about the interrupt structure of 8051 microcontroller. These are the learning outcomes of this video. Student will be able to compare the approach of with the polling, interrupt approach with the polling. Rather student will be able to find out what are the advantages of using interrupt as well. Student will be able to use this interrupt for handling different interrupt related tasks. So these are the contents, we will go through the introduction, then we will compare how interrupt is a better approach as compared to the polling approach. And then we will go through the interrupt structure, very special function registers which are related to the interrupt, we will go through these two special function registers called as IE and IP register. And at last we will see different steps which are followed by the 8051 microcontroller whenever a particular interrupt is handled by the microcontroller. Let us start, how a single microcontroller can serve several devices? Let us take one example, two switches are connected and you want LED should be on corresponding to every switch when a particular switch is closed, switch one is closed LED one should be on when switch two is closed LED two should be on. So this can be done by using an approach called as polling approach. So several devices can be served by two different approaches, one is called as polling where you can think of microcontroller is continuously checking for the port pins and when port pin corresponding to LED one is switched on the LED one will on like that. But the best approach or best solution for this will be interrupt, what is interrupt? So interrupt is basically an event, it is external event or it may be internal event if it is external event it will be called as external interrupt if it is internal event it is called as internal interrupt. So it is event that disturbs the normal execution of a program and disturbing the normal execution it changes the execution sequence. Just take one example, this is main program you want to execute, so you know microcontroller is doing sequential execution, instructions are executed one by one. But whenever some event occurs called as interrupt what happens is interrupt occurs whenever main program is getting executed is because of occurrence of the interrupt the execution sequence changes to something called as interrupt service routine. When it goes to interrupt service routine one responsibility of the programmer is context saving. As well microcontroller itself does some sort of saving of the contents of the program counter onto the stack memory that we will see in the steps which are to be followed. Context saving at the end of interrupt service routine microcontroller should restore those contests and execute instruction called as RETI. At the end of interrupt service routine what is expected is you should write instruction called as RETI and after writing after execution of the instruction RETI again the execution of the main program starts. Now what are the different sources of this event? What are the different sources of interrupt in 8051 microcontroller? So first source is timer so there are two timers so two interrupts are possible because of the timer, timer zero interrupt, timer one interrupt then external hardware interrupts are there there are two pins of microcontroller related to the interrupts so int0 and int1 and at last fifth interrupt may be because of the serial communication so UART is the module available in 8051 microcontroller so that may also result into the interrupt. Now let us go through the spatial function registers which are related to the handling of the interrupts. So there are two spatial function registers out of one is interrupt enable register called as IE. If you look at IE is a 8-bit spatial function register most significant bit of this IE register is EA. This EA stands for global interrupt enable bit so if EA bit is zero then all interrupts are disabled and if you want to make the use of any interrupt this EA bit has to be one. Then this ET2 is related to the timer 2 which is not available in 8051 we will neglect it but this ES corresponding to the enabling the serial communication interrupt ET timer one interrupt enabling external interrupt enabling timer zero interrupt enabling and then external interrupt int0 bar if you want to enable it. So you can enable or disable a particular interrupt. So you can think of these are the local enable bits for individual interrupt while this is a global interrupt enable bit if this bit is zero there is no meaning for these set and reset conditions of these bits like that there is one more register called as IP register interrupt priority register. Now interrupt is an external event when interrupt occurs execution sequence changes fine but when more than one interrupts are occurring simultaneously then what happens which interrupts interrupt service routine gets executed. So this IP register is used for deciding priorities manually as well there is default priority for the interrupt assigned where the interrupt int0 bar has got highest priority by default and serial communication has got lowest priority. But suppose you want to make serial communication interrupt itself with highest priority what you can do is you can write one in its corresponding bit for interrupt in interrupt priority register all other bits you make it zero. So you are giving high priority to the serial communication interrupt itself. So let us go through the interrupt structure. So you will find that in the interrupt structure these are the five sources of the interrupt and then because of occurrence of the interrupt what first thing happens is its corresponding interrupt flag gets set if it is in external interrupt zero int0 bar interrupt i0 flag will be set if it is a timer zero interrupt timer zero flag will be set. But just setting the flag is not sufficient to cause change in the execution sequence there are few requirements first thing first requirement is its interrupt corresponding interrupt flag should be set fine. Let us take one example let us say we are talking about external interrupt int1 bar you get a signal change on to the pin fine when the signal change you are getting there is one bit control bit called as IT interrupt type. So you can have level triggered interrupt or edge triggered interrupt fine. So suppose that interrupt is occurring and because of occurrence of that particular interrupt is corresponding flag bit is set then it is not sufficient to occur the interrupt change in execution sequence will not just occur because of the flag bit is set. So that interrupt should be locally enable as well the interrupt should be globally enable if you look at this this is a global enable bit. So this should be globally enable and then assuming that this interrupt itself has got highest priority at the stage when the interrupt has occurred then only its corresponding interrupt service routine will get executed. So these are the interrupt vector addresses whenever interrupt occurs execution sequence changes to this predefined addresses. So these are the predefined addresses. So actually interrupt 0 corresponds to address 0 0 0 3 like that serial communication corresponds to address 0 0 2 3. Only one thing at the end of ISR if you write RETI automatically these flag bits are cleared but for serial communication it is responsibility of the programmer to clear this particular bit. Now how exactly the interrupt is handled at last we will tight understand with the help of the steps first microcontroller finishes the current execution stores the contents of the PC which is the address of next instruction on to the stack as well you can have some context saving it saves the interrupt logic internally not on to the stack then it jumps to the fixed address decided by the interrupt vector address which we discuss in the previous slide then microcontroller gets that address and interrupt service routine which is corresponding to that particular address starts getting executed and at the end user will be writing the instruction RETI because of that from interrupt service routine the contents of the program counter which were pushed or stored on to the stack are popped back these two bytes are popped back and then microcontroller starts execution from the previous address of the main program itself which was stored on to the stack memory this is how microcontroller handles the interrupt by the interrupt structure which is available with the help of interrupt structure available for the 8051 microcontroller so these are the references used for this video presentation thank you