Interrupt Using ARM7

Description

Interrupt is one of the powerful concepts in microcontroller applications. If an interrupt occurs in the microcontroller, controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine(ISR).

  • ISR is a piece of code that tells the controller what to do when the interrupt occurs.
  • After the execution of ISR,controller returns back to the instruction.

Types Of Interrupt

Two types of interrupt
1.Hardware interrupt.
2.Software interrupt.

Hardware interrupt

If the interrupts are generated by the interfaced devices like a switch is called hardware interrupt.

Software interrupt

Interrupts are generated by a piece of code is called software interrupt.

Interrupt In Lpc21xx

  • When an IRQ arrives to the CPU, it stops executing the current code and starts executing the ISR. After the ISR execution has finished the CPU gets back to where it had stopped.
  • Interrupts in LPC214x are handled by Vectored Interrupt Controller(VIC) and are classified into 3 types.
    1. Fast Interrupt Request (FIQ).
    2. Vectored Interrupt Request (Vectored IRQ).
    3. Non-Vectored IRQ.
  • Vectored-The CPU is aware of the address of the ISR when the interrupt occurs.
  • Non-Vectored- The CPU doesn’t know the address of the ISR nor the source of the IRQ when the interrupt occurs and it needs to be supplied by the ISR address.

Interrupt Register

  • VICIntSelect (R/W) :
    The register is used to select an interrupt as IRQ or as FIQ.
    When bit is set to 0 = IRQ
    When bit is set to 1 = FIQ
  • VICIntEnable (R/W) :
    To enable interrupts.
    When bit is set to 0 = Disable Interrupt
    When bit is set to 1 = Enable Interrupt
  • VICIntEnClr (R/W) :
    Register is used to disable interrupt.
    When bit is set to 1 = Disable Interrupt
    When bit is set to 0 = No Effect
  • VICIRQStatus (R) :
    Reading the current status of the enabled IRQ interrupts.
    When bit is set to 1 = Interrupt is Enable
    When bit is set to 0 = No Effect
  • VICFIQStatus (R) :
    Reading the current status of the enabled FIQ interrupts.
    When bit is set to 1 = Interrupt is Enable
    When bit is set to 0 = No Effect
  • VICSoftInt :
    It is used to generate interrupts using software
    When bit is set to 1 = Triggered Interrupt
    When bit is set to 0 = No Effect
  • VICSoftIntClear :
    This register is used to clear the interrupt request When bit is set to 1 = Clear Interrupt
  • VICVectCntl0 to VICVectCntl15 (16 registers in all) :
    These are the Vector Control registers. These are used to assign a particular interrupt source to a particular slot.
  • VICVectAddr :
    Interrupt is Triggered this register holds the address of the associated ISR
  • VICDefVectAddr :
    This register stores the address of the default/common ISR that must be called when a Non-Vectored IRQ occurs.

Code

 #include <LPC21xx.H>
 void lcdcmd(unsigned char);
 void lcd_init(void);
 void lcddata(unsigned char*);
 void delay(unsigned int);
 void ext_interrupt(void);
 void intr(void)__irq;
 
 unsigned char d=0;
 int main(void)
 {
 lcd_init();
 ext_interrupt();
 while(1)
 {
 if(d==1)
 {
 lcdcmd(0xc0);
 lcddata("ok");
 }
 }
 }
 
 void ext_interrupt()
 {
 VICVectAddr0=(unsigned long)intr;
 IODIR0=IODIR0 | 0x007FB400;
 IODIR1=IODIR1 | 0x01E00000;
 IOCLR1=IOCLR1 | 0x01E00000;
 PINSEL0=PINSEL0 | 0x20000000;//setting P0.14 as EINT1
 VICIntSelect=0x00000000;//selecting as IRQ
 VICVectCntl0 = 0x20 | 15;//alloting a slot0 for EINT1
 VICIntEnable=0x00008000; //enbling EINT1
 }
 
 void intr(void)__irq
 {
 lcddata("interrupt occured");
 d=1;
 EXTINT=0x02; //clearing the interrupt
 VICVectAddr=0;
 }
 
 void lcd_init()
 {
 IODIR0=IODIR0 | 0x00FF2400;
 lcdcmd(0x01);
 lcdcmd(0x38);
 lcdcmd(0x0E);
 lcdcmd(0x06);
 lcdcmd(0x80);
 }
 
 void lcdcmd(unsigned char a)
 {
 IO0CLR=IO0CLR | (1<<10);//making rs=0 for command reg
 IO0SET=IO0SET | (a<<16); //loading cmd to DO to D7
 IO0SET=IO0SET | (1<<13);//making en=1
 delay(1000);
 IO0CLR=IO0CLR | (1<<13);//making en=0
 IO0CLR=IO0CLR | (a<<16);
 }
 
 void lcddata(unsigned char *a)
 {
 unsigned char i=0;
 for(i=0;a[i]!='\0';i++)
 {
 IO0SET=IO0SET | (1<<10);//making rs=1 for data reg
 IO0SET=IO0SET | (a[i]<<16);//loading data to D0 to D7
 IO0SET=IO0SET | (1<<13);//making en=1
 delay(1000);
 IO0CLR=IO0CLR | (1<<13);//making en=0
 IO0CLR=IO0CLR | (a[i]<<16);
 }
 }
 
 void delay(unsigned int count)
 {
 int i,j;
 for(i=0;i<count;i++)
 for(j=0;j<i;j++);
 } 

Leave a Reply

Your email address will not be published. Required fields are marked *