Wednesday, 22 August 2012

External Interrupt - (LPC2148)

External Interrupt - BlueBoard_schematics_V1R1-3(LPC2148)

aim - when ext pin press buzzer rings



----------------------------------------------
eint2.h
----------------------------------------------


#ifndef __EINT2_H_
#define __EINT2_H_

#define EINT2_PINSEL PINSEL0
#define EINT2_PIN (1<<31)
#define EINT2_CHNL (1<<16)
#define LED_PIN (1<<25) //buzzer
#define LED_DIR IO1DIR
#define LED_CLR IO1CLR
#define LED_SET IO1SET

void initGPIO(void);
void initEINT2(void);
void beep(void);
void delay(void);
void lowBeep(void);
void lowDelay(void);

#endif


--------------------------------------------------
eint2.c
--------------------------------------------------

#include "Eint2.h"
#include <LPC214X.H>

void initGPIO(void)
{
LED_DIR |= LED_PIN; //setup buzzer
LED_SET = LED_PIN;
}

void ExtInt_ISR(void) __irq
{
EXTINT   = 0x00000004;
lowBeep();
VICVectAddr = 0x00;
}

void initEINT2(void)
{
EINT2_PINSEL |= EINT2_PIN;
VICDefVectAddr = (unsigned)ExtInt_ISR;
VICIntEnable |= EINT2_CHNL;
}

void beep()
{      
LED_CLR |= LED_PIN;
lowDelay();
LED_SET |= LED_PIN;
lowDelay();
}

void lowBeep()  //buzzer beeping
{      
LED_CLR |= LED_PIN;
lowDelay();
LED_SET |= LED_PIN;
lowDelay();
}

void delay()
{
int i=0, j=0;
for(i=0;i<3000;i++)
for(j=0;j<2000;j++);
}

void lowDelay()
{
int i=0, j=0;
for(i=0;i<3000;i++)
for(j=0;j<50;j++);
}


-------------------------------------------------------------------------
main.c
-------------------------------------------------------------------------

#include <LPC214X.H>
#include "Eint2.h"

main()
{
initGPIO();
initEINT2();

lowBeep();
while(1)
{
// beep();
}
}
-----------------------------------------------------------------------------

No comments:

Post a Comment