0% found this document useful (0 votes)
69 views4 pages

Notes 1

The document demonstrates using an external interrupt on pin P0.16 connected to EINT0 to toggle an LED connected to pin P0.30. It defines the external interrupt service routine Extint0_Isr() to turn the LED on then off after a delay. The main program configures EINT0 for falling edge detection, assigns the ISR, enables the interrupt, and waits in a loop for interrupts to occur and toggle the LED.

Uploaded by

Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views4 pages

Notes 1

The document demonstrates using an external interrupt on pin P0.16 connected to EINT0 to toggle an LED connected to pin P0.30. It defines the external interrupt service routine Extint0_Isr() to turn the LED on then off after a delay. The main program configures EINT0 for falling edge detection, assigns the ISR, enables the interrupt, and waits in a loop for interrupts to occur and toggle the LED.

Uploaded by

Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

// The program demonstrates the use of

//external interrupt EINT0 to increment


//a LED based 4-bit binary counter

#include<lpc214x.h>

__irq void Extint0_Isr(void); //declaration of ISR

unsigned static int count=0;


int main(void)

{
unsigned int delay1,j;

IO0DIR =0X0000000F;//set p0.0 to p0.3 direction as output pins

PINSEL1 =0X00000001;//Setup P0.16 AS EINT0

EXTMODE =0x01; //edge i.e falling edge trigger and active low

EXTPOLAR= 0X00;

VICVectAddr0 = (unsigned long) Extint0_Isr; //Assign the EINT0 ISR function

VICVectCntl0 = 0x20 | 14; //Assign the VIC channel EINT0 to interrupt priority 0

VICIntEnable |= 0x00004000; //Enable the EINT0 interrupt

count = 0x00000000;

__irq void Extint0_Isr(void) //whenever there is a low level on EINT0


{
unsigned int j;
if(count==16)
{count=0x00000000;}
else
{IO0CLR = 0x0000000F;
IO0SET = count++;}

EXTINT |=0X00000001; //Clear interrupt


VICVectAddr=0; //Acknowledge Interrupt
}
// The program demonstrates About the External interrupt to the Controller

#include<lpc214x.h>

__irq void Extint0_Isr(void); //declaration of ISR

int main(void)

{
unsigned int delay1;
PINSEL1 = 0X00000000;//SET P0.16 AS GPIO PIN

IO0DIR =0X00010000;//set p0.16 direction as output pin

PINSEL0 =0X0000000C;//Setup P0.1 AS EINT0

IO0CLR =0X00010000;//switch off the LED connected to pin P0.16

EXTMODE =0x01; //edge i.e falling egge trigger and active low

EXTPOLAR= 0X00;

VICVectAddr0 = (unsigned long) Extint0_Isr; //Assign the EINT0 ISR function

VICVectCntl0 = 0x20 | 14; //Assign the VIC channel EINT0 to interrupt priority 0

VICIntEnable |= 0x00004000; //Enable the EINT0 interrupt

while(1) //waiting for interrupt to occur


{

for(delay1=0;delay1<800;delay1++); //some delay to sense interrupt.

}
}

void Extint0_Isr(void)__irq //whenever there is a low level on EINT0


{
unsigned int delay;
IO0SET = 0X00010000;
for(delay = 0; delay<1650000; delay++); //delay

IO0CLR = 0X00010000;

EXTINT |=0X00000001; //Clear interrupt


VICVectAddr=0; //Acknowledge Interrupt
}
#include <LPC214X.H>
/*****************DAC Functions***************/

int main(void)
{
unsigned int in_data;
unsigned int temp;

in_data = 0x2FF;

temp = in_data << 6;

DACR = temp;

for(;;);
}
#include <LPC214X.H>
/*****************ADC Functions***************/
//AD0.3 or P0.30 will be used in this program
int main(void)
{
unsigned int adc_data;
unsigned int i;

IO0DIR = 0X000003FF;
/*************Initialize ADC AD0.4*************/

AD0CR = 1<<21;//A/D is Operational now from power down mode

PINSEL0 = 0x00000000;

//SET P0.30 AS ADC INPUT PIN


PINSEL1 = 0x10000000;

//SELECT CHANNEL AD0.3


AD0CR |= 0X00000008;

//SELECT CLOCK DIVISOR AS 8


AD0CR |= 0X00000800;

while(1)
{
//POWER UP THE ADC FROM SLEEP MODE
AD0CR |= 1<<21;

//START CONVERSION
AD0CR |= 1<<24;

//Wait untill the DONE bits Sets


while(!(AD0GDR & 0x80000000));

//STOP CONVERSION
AD0CR |= 0<<24;

//RIGHT SHIFT THE 10-BIT RESULT


adc_data = AD0DR3 >> 6;
adc_data = adc_data & 0x000003FF; //Clearing all other Bits

IO0CLR = 0XFFFFFFFF;
IO0SET = adc_data;
for(;;); //wait before next conversion
}
}

You might also like