Spread the love

interrupts of arm7 ( LPC2148 )

__________________________________________________________________________________________________


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

  1. 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
  2. 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.

interrupts of arm7 ( LPC2148 )

 

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.

 

Vector no

Program address

source

Interrupt detail

Interrupt name(used in programming)

1

0000

RESET

Power on RESET

Not programmable

2

0002

INT0

External interrupt 0

INT0_vect

3

0004

INT1

External interrupt 1

INT1_vect

4

0006

INT2

External interrupt 2

INT2_vect

5

0008

TIMER2 COMP

Timer/counter2 compare match

TIMER2_COMP_vect

6

000A

TIMER2 OVF

Timer/counter2 overflow

TIMER2_OVF_vect

7

000C

TIMER1 CAPT

Timer/counter1 capture event

TIMER1_CAPT_vect

8

000E

TIMER1 COMPA

Timer/counter1 compare match A

TIMER1_COMPA_vect

9

0010

TIMER1 COMPB

Timer/counter1 compare match B

TIMER1_COMPB_vect

10

0012

TIMER1 OVF

Timer/counter1 overflow

TIMER1_OVF_vect

11

0014

TIMER0 COMP

Timer/counter0 compare match

TIMER0_COMP_vect

12

0016

TIMER0 OVF

Timer/counter0 overflow

TIMER0_OVF_vect

13

0018

SPI, STC

Serial transfer complete

SPI_STCvect

14

001A

USART, RXC

USART, Rx complete

USART0_RX_vect

15

001C

USART, UDRE

USART, data register empty

USART0_UDRE_vect

16

001E

USART, TXC

USART, Tx complete

USART0_TX_vect

17

0020

ADC

ADC conversion complete

ADC_vect

18

0022

EE_RDY

EEPROM ready

EE_RDY_vect

19

0024

ANA_COMP

Analog comparator

ANALOG_COMP_vect

20

0026

TWI

Two wire serial interface

TWI_vect

21

0028

SPM_RDY

Stored program memory ready

SPM_RDY_vect

         

 

 

 

Applications

To provide services to the devices efficiently.

1.CIRCUIT DIAGRAM of Interrupts of ARM7 ( LPC2148 ) 

CIRCUIT DIAGRAM of Interrupts of ARM7 ( LPC2148 )

1. PROGRAM of Interrupts of ARM7 ( LPC2148 )

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- INTERRUPT OF ARM7(LPC21XX),INTERRUPT 0 CONTROL LED BLINKING AND 
INTERRUPT 1 CONTROL LCD  
******************************************************/

#include <lpc21xx.h>   // header file of arm controller

#include "delay.h"  // delay header file

#include "lcd4bit.h"  // header file of lcd 

int ar[10]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f };// common cathode code
int count=0;  // varible of type int

void interrupt_ini(); // interrupt intilization

int main()    // start of main program
  {
		PINSEL0=0X00000000;       // port0.0 to port0.15 used as gpio mode
		PINSEL1=0X00000000;       // port0.16 to port0.31 used as gpio mode
		PINSEL2=0X00000000;       // port1.16 to port1.32 used as gpio mode
		IO0DIR=0X0fFFFFFF;       // direction of port0.0 to port0.31 worked as output mode
		IO1DIR=0XFFFFFFFF;       // direction of port1.0 to port1.31 worked as output mode
		lcd_ini();               // lcd initilization function
		interrupt_ini();         // interrupt intilization function
		while(1)                 
	   	{
					IO1SET|=(ar[count]<<16);
					delay_fv(1000,1000);
					IO1CLR|=(ar[count]<<16);
					count++;
					if(count==10)
						   count=0;
		  }
		return 0;
  }
	
void interrupt_0()__irq   // interrupt 0
  {
		EXTINT=0X01;
		IO0SET|=(0XFF<<16);
		delay_fv(500,1000);
		IO0CLR|=(0XFF<<16);
		delay_fv(500,1000);
	
  }	

void interrupt_1()__irq  // interrupt 1
	{
			EXTINT=0X02;
			cmd(0x01);
			lcd_str("WELCOME TO");
			cmd(0xc0);
			lcd_str("FIRMCODES.COM");
			delay_fv(1000,1000);
	}	
	
void interrupt_ini()
  {
		/* intialize interrupt 0*/
		PINSEL0|=0x0c;
		VICVectAddr0=(unsigned)interrupt_0;
		VICVectCntl0=0x20|14;
		VICIntEnable=1<<14;
	 // delay_fv(1000,100);
		
		/* intialize interrupt 1*/
		PINSEL0|=0xc0;
		VICVectAddr1=(unsigned)interrupt_1;
		VICVectCntl1=0x20|15;
		VICIntEnable=1<<15;
  }	

DELAY.H  HEADER FILE

/*********************************************************************
DELAY.H HEADER FILE
***********************************************************************/

void delay_ff()
{
    unsigned int b,v;
    for(b=0;b<600;b++)
    for(v=0;v<100;v++);
}

void delay_pf(unsigned int x)
   {
      unsigned int i,j;
      for(i=0;i<x;i++)
        for(j=0;j<153;j++);
   }

void delay_fv(unsigned int x,int y)
  {
      unsigned int i,j;
      for(i=0;i<x;i++)
          for(j=0;j<y;j++);
  }

void delay_ms(int count)
  {
      int j=0,i=0;
      for(j=0;j<count;j++)
          {
    /* At 60Mhz, the below loop introduces
    delay of 10 us */
               for(i=0;i<35;i++);
           }
   }

LCD4BIT.H  HEADER FILE

/*******************************************************************
LCD4BIT.H HEADER FILE
*********************************************************************/
#define LCD (0xf<<11)
#define RS (1<<8)
#define RW (1<<9)
#define EN (1<<10)


void lcd_display(unsigned char x)
  {
			unsigned int temp;
			delay_ms(1000);
			IO0CLR|=(RS|RW|EN|LCD);
			temp=(x>>4)&0x0f;
			//delay_ms(10);
		  IO0SET|=RS;
		  IO0CLR|=RW;
		  IO0SET|=EN;
			IO0CLR|=LCD;
		  IO0SET|=(temp<<11);
			delay_ms(100);
			IO0CLR|=EN;
			
			delay_fv(10,10);
			IO0CLR|=(RS|RW|EN|LCD);
			temp=x&0x0f;
			//delay_ms(1000);
		  IO0SET|=RS;
		  IO0CLR|=RW;
		  IO0SET|=EN;
			IO0CLR|=LCD;
		  IO0SET|=(temp<<11);
			delay_ms(100);
		  IO0CLR|=EN;
			delay_ms(100);
  }

void cmd(unsigned char x)
  {
			unsigned int temp;
			delay_ms(100);
			temp=(x>>4)&0x0f;
			IO0CLR|=(RS|RW|EN);
		  IO0CLR|=RS;
		  IO0CLR|=RW;
		  IO0SET|=EN;
		  IO0CLR|=LCD;
		  IO0SET|=(temp<<11);
		  delay_ms(100);
		  IO0CLR|=EN;
			
			delay_fv(100,10);
			IO0CLR|=(RS|RW|EN);
			temp=x&0x0f;
		  IO0SET|=(temp<<11);
		  IO0CLR|=RS;
		  IO0CLR|=RW;
		  IO0SET|=EN;
			IO0CLR|=LCD;
		  IO0SET|=(temp<<11);
		  delay_ms(100);
		  IO0CLR|=EN;
		  delay_fv(100,100);	
  }

void lcd_ini()
  {
		PINSEL0|=(0XFF<<8);
		IO0DIR|=(0XF<<8);
		cmd(0X02);
	  cmd(0X28);
	  // cmd(0X02);
	  cmd(0x0e);
		cmd(0X06);
		cmd(0X01);
		cmd(0X80);
  }


void lcd_str(unsigned char *str)
 {
		while(*str!='\0')
	  	{
	    	lcd_display(*str);
	     	str++;
	    }
 }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

______________________________________________________________________________________________________

Content for the tab VIDEO