Spread the love
____________________________________________________________________________________________________
- What is interrupt ? – An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service.
- Why we need interrupt? – A single microcontroller can serve several devices by two ways
- Interrupt-Whenever any device needs its service, the device notifies the microcontroller by sending it an interrupt signal. Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and serves the device. The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler
- Polling- The microcontroller continuously monitors the status of a given device. When the conditions met, it performs the service. After that, it moves on to monitor the next device until every one is serviced
- Advantage of interrupt– The polling method is not efficient, since it wastes much of the microcontroller’s time by polling devices that do not need service. The advantage of interrupts is that the microcontroller can serve many devices, Each devices can get the attention of the microcontroller based on the assigned priority . For the polling method, it is not possible to assign priority since it checks all devices in a round-robin fashion.
- How does interrupt works? –
- Whenever any device needs its service, the device notifies the microcontroller by sending it an interrupt signal.
- Upon receiving an interrupt signal, the microcontroller interrupts whatever it is doing and saves the address of the next instruction (PC) on the stack pointer (SP).
- It jumps to a fixed location in memory, called the interrupt vector table, that holds the address of the ISR(interrupt service routine). Each interrupt has its own ISR. The microcontroller gets the address of the ISR from the interrupt vector table and jumps to it
- It starts to execute the interrupt service subroutine until it reaches the last instruction of the subroutine which is RETI (return from interrupt).RETI not used in C coding.
- Upon executing the RETI instruction, the microcontroller returns to the place where it was interrupted and First, it gets the program counter (PC) address from the stack pointer by popping the top two bytes of the stack into the PC
- Then it starts to execute from that address and continue what it executing before.
- This whole process is shown graphically in above pics.
- Interrupt vector table –Interrupt vector table shows priority of different interrupts. As below table shown,Reset has highest priority among all interrupt and serial COM(USART) has lowest. Priority is high to low as Reset to serial COM. Upon Reset, all interrupts are disabled (masked), meaning that none will be responded to by the microcontroller if they are activated. There are 6 total interrupts in 8051 microcontroller. First is Reset, two hardware external interrupt INT0 and INT1, two Timer interrupt TF0 and TF1 and last one is serial com interrupt that is for both receiver and transmitter.
no | Interrupt | ROM address | Pin |
1 | Reset | 0000 | 9 |
2 | External HW (INT0) | 0003 | P3.2 (12) |
3 | Timer 0 (TF0) | 000B | |
4 | External HW (INT1) | 0013 | P3.3 (13) |
5 | Timer 1 (TF1) | 001B | |
6 | Serial COM (RI and TI) | 0023 | |
- Applications – To provide services to the devices efficiently.
Click Here : understanding of RESET interrupt
Click Here : understanding of External interrupt INT0 & INT1
Click Here : understanding of Timer interrupt TF0 & TF1
Click Here : understanding of Serial interrupt
1. circuit diagram of external interrupts in 8051 microcontroller
____________________________________________________________________________________________________
2. circuit diagram of serial communication interrupts in 8051
____________________________________________________________________________________________________
3. circuit diagram of 8051 with led in which blinking of led is due to timer 0 interrupt
1. Program Of external interrupts of 8051 , In Which Interrupt 0 control 7 Segment And Interrupt 1 Control LCD Display
/****************************************************** IDE :- Keil DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com) WHAT PROGRAM DO:- Interrupt 0 LED BLINKING And Interrupt 1 Control LCD Display and normal mode counting of 7 SEGMENT ******************************************************/ #include<reg51.h> sfr seven_seg=0x80; // 7segment at port 0 sfr led=0xa0; // led at port 2 sfr lcd=0x90; // data of lcd at port 1 sbit rs=P3^5; // rs pin at P3.5 sbit rw=P3^6; // rw pin at P3.6 sbit en=P3^7; // en pin at P3.7 void delay(); // delay function void cmd(); void display(); void main() { int data1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; // data of common anode int i,j; IE=0x85; // extrnal interrupt are enabled while(1) { if(i==10) i=0; seven_seg=data1[i]; delay(); delay(); delay(); i++; } } void led_control() interrupt 0 // interrupt(INT0) 0 { led=0x00; delay(); led=0xff; delay(); } void lcd_control() interrupt 4 // interrupt(INT1) 1 { lcd=0x38; cmd(); lcd=0x0e; cmd(); lcd=0x01; cmd(); lcd=0x06; cmd(); lcd=0x80; cmd(); lcd='W'; display(); lcd='E'; display(); lcd='L'; display(); lcd='C'; display(); lcd='O'; display(); lcd='M'; display(); lcd='E'; display(); lcd=' '; display(); lcd='T'; display(); lcd='O'; display(); lcd=0xc0; cmd(); lcd='F'; display(); lcd='I'; display(); lcd='R'; display(); lcd='M'; display(); lcd='C'; display(); lcd='O'; display(); lcd='D'; display(); lcd='E'; display(); lcd='S'; display(); lcd='.'; display(); lcd='C'; display(); lcd='O'; display(); lcd='M'; display(); } void delay() // delay function { unsigned int i,j; for(i=0;i<100;i++) for(j=0;j<153;j++); } void cmd() { unsigned char i; rs=0; rw=0; en=1; for(i=0;i<2;i++); en=0; delay(); } void display() { unsigned char i; rs=1; rw=0; en=1; for(i=0;i<2;i++); en=0; delay(); }
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
____________________________________________________________________________________________________
2. PROGRAM OF SERIAL COMMUNICATION INTERRUPT IN WHICH DATA SEND FROM PC OR LAPTOP IS DISPLAYED ON LCD
/****************************************************** IDE :- Keil DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com) WHAT PROGRAM DO:- INTERRUPT OF SERIAL COMMUNICATION,DATA ENTERED FROM PC DISPLAYs ON LCD CONNECTED WITH 8051 ******************************************************/ #include<reg51.h> sfr lcd=0xa0; // data of lcd at port 2 sbit rs=P3^5; // rs pin at P3.5 sbit rw=P3^6; // rw pin at P3.6 sbit en=P3^7; // en pin at P3.7 void delay(); // for delay void cmd(); // lcd in command mode void display(); // lcd is in display mode char serial_receive(); // initialize controller to work as serial communication void serial_initialize(); // receive data to controller via rxd pin to computer,s hyper terminal void serial_transmit(unsigned char x); // transmit data to computer's hyper terminal from controller via txd pin unsigned rec; // gloable variable void main() { int x=0; serial_initialize(); // call the initialize function // initialization of lcd lcd=0x38; cmd(); lcd=0x0e; cmd(); lcd=0x01; cmd(); lcd=0x06; cmd(); lcd=0x80; cmd(); while(1); } void serial_interrupt() interrupt 4 { if(RI==1) { rec=serial_receive(); lcd=rec; display(); } } void serial_initialize() { TMOD=0x20; //timer 1 in mode2 (8-bit auto-reload) to set baud rate TH1=0xfd; // to make baud rate of 9600hz , crystal oscillator =11.0592Mhz SCON=0x50; //make SM0=0 and SM1=1 present in SCON register, //so that we select, Serial Mode 1, 8-bit data,1 stop bit, 1 start bit // make REN=1 present in SCON register ,it allows 8051 to receive data on RxD pin TR1=1; // to start timer IE=0X90; // to make serial interrupt interrupt enable } char serial_receive() { // RI bit is present in SCON register while(RI==0); // wait untill hole 8 bit data is received completely. RI bit become 1 when reception is compleated rec=SBUF; // data is received in SBUF register present in controller during receiving RI=0; // make RI bit to 0 so that next data is received return rec; // return rec where funtion is called } void serial_transmit(unsigned char x) { SBUF=x; // 8 bit data is put in SBUF register present in controller to transmit // TI bit is present in SCON register while(TI==0); // wait untill transmission is compleated. when transmittion is compleated TI bit become 1 TI=0; // make TI bit to zero for next transmittion } void cmd() { unsigned char i; rs=0; rw=0; en=1; for(i=0;i<2;i++); en=0; delay(); } void display() { unsigned char i; rs=1; rw=0; en=1; for(i=0;i<2;i++); en=0; delay(); } void delay() { unsigned int i,j; for(i=0;i<100;i++) for(j=0;j<153;j++); }
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
____________________________________________________________________________________________________
3. PROGRAM OF TIMER 0 INTERRUPT IN WHICH LED BLINKING IS CONTROLLED
/****************************************************** IDE :- Keil DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com) WHAT PROGRAM DO:- TIMER INTERRUPT TO CONTROL LED BLINKING ******************************************************/ #include<reg51.h> sfr led=0x90; void main() { TMOD=0X01; // MODE 1 OF TIMER O IS SELECTED TL0=0X00; TH0=0X00; IE=0X82; TR0=1; led=0x00; while(1); } void timer_0() interrupt 1 { led=~led; // toggle the port 1 }
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
____________________________________________________________________________________________________
Content for the tab VIDEO