____________________________________________________________________________________________________
- 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 service of microcontroller, 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. Upon Reset, all interrupts are disabled (masked), meaning that none will be responded to by the microcontroller if they are activated. There are 21 total interrupts in ATmega32 microcontroller.
|
- Applications – To provide services to the devices efficiently.
Click Here : understanding of interrupt as program point of view
1. PROGRAM OF EXTERNAL INTERRUPTS IN ATMEGA16, INT0 CONTROL LCD AND INT2 CONTROL LED BLINKING
/****************************************************** www.firmcodes.com DEVELOPED BY:- FIRMWARE DEVELOPER WHAT PROGRAM DO:- INTO CONTROL LCD AND INT1 CONTROL LED BLINKING ******************************************************/ #include<avr/io.h> #include<util/delay.h> #include<avr/interrupt.h> #include"lcd.h" void main() { sei(); // globle interrupt enable MCUCSR=0x40; MCUCR=0X04; GICR|=(1<<INT1)|(1<<INT2); // interrupt 1 is enable DDRB=0x00; // PORTB is in output mode DDRD=0XF7; DDRA=0XFF; /* pin 4 is act as input and rest of pin act as ouput*/ init_LCD(); while(1) { PORTA=0X0F; // led is on _delay_ms(50); PORTA=0X00; // led is off _delay_ms(50); } } ISR (INT1_vect) { int i=10; while(i--) { dis_cmd(0X01); // clear lcd LCD_write_string("ISR INTERRUPT 1........."); } } ISR (INT2_vect) { int i=50; while(i--) { PORTA=0XF0; // led is on _delay_ms(50); PORTA=0X00; // led is off _delay_ms(50); } }
LCD.H
/*LCD.H HEADER FILE*/ #define ctrl PORTD #define en 2 // enable signal #define rw 1 // read/write signal #define rs 0 // register select signal void init_LCD(void) { dis_cmd(0x02); // to initialize LCD in 4-bit mode. _delay_ms(1); dis_cmd(0x28); //to initialize LCD in 2 lines, 5X7 dots and 4bit mode. _delay_ms(1); dis_cmd(0x01); // clear LCD _delay_ms(1); dis_cmd(0x0E); // cursor ON _delay_ms(1); dis_cmd(0x80); // —8 go to first line and –0 is for 0th position _delay_ms(1); return; } void dis_cmd(char cmd_value) { char cmd_value1; cmd_value1 = cmd_value & 0xF0; //mask lower nibble //because PA4-PA7 pins are used. LCD_cmd(cmd_value1); // send to LCD cmd_value1 = ((cmd_value<<4) & 0xF0); //shift 4-bit and //mask LCD_cmd(cmd_value1); // send to LCD } void dis_data(char data_value) { char data_value1; data_value1=data_value & 0xF0; LCD_write(data_value1); data_value1=((data_value<<4) & 0xF0); LCD_write(data_value1); } void LCD_cmd(unsigned char cmd) { ctrl=cmd; ctrl&=~(1<<rs); ctrl&=~(1<<rw); ctrl|=(1<<en); _delay_ms(1); ctrl&=~(1<<en); _delay_ms(10); return; } void LCD_write(unsigned char data) { ctrl= data; ctrl|=(1<<rs); ctrl&=~(1<<rw); ctrl|=(1<<en); _delay_ms(1); ctrl&=~(1<<en); _delay_ms(10); return ; } void LCD_write_string(unsigned char *str) //store address value of the string in pointer *str { int i=0; while(str[i]!='\0') // loop will go on till the NULL character in the string { dis_data(str[i]); // sending data on LCD byte by byte i++; } return; }
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
________________________________________________________________________________________________________________________________________
Content for the tab VIDEO