⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 ARM7_mulIRQ LPC21xx多中断程序
💻 C
字号:
#include <LPC21XX.H>
#define LED1 0x02000000	/*LED1接在P0.25上*/
#define LED0 0x01000000	/*LED0接在P0.24上*/	
typedef unsigned int uint32;
void Eint1_ISR(void) __attribute__ ((interrupt));				/*声明某函数为中断服务子程序的方法*/
void Eint0_ISR(void) __attribute__ ((interrupt));
uint32 times = 40;			/*循环次数默认为40*/
void delay40(void)  {                         
  unsigned volatile long i,j;
  for(i=0;i<10000;i++)
  for(j=0;j<times;j++)
  ;
  if(times > 40){
  	times-=2;
  }else if(times <40){
  	times+=2;
  }
}
void Eint0_ISR(void){  
  times = 0;
  while(times!=40){
	IO0CLR = LED0;
	delay40();
	IO0SET = LED0;
	delay40();  	
  }
  while((EXTINT&0x01)!=0){
   EXTINT=0x01;                   /*清除EINT0中断标志*/
  }
  VICVectAddr=0x00;
}
void Eint1_ISR(void){
  times = 0;
  while(times!=40){
	IO0CLR = LED1;
	delay40();
	IO0SET = LED1;
	delay40();  	
  }
  while((EXTINT&0x02)!=0){
  	EXTINT=0x02;                   /*清除EINT1中断标志*/
  }
  VICVectAddr=0;
}
int  main(void)
	{
	IO0DIR = LED1|LED0;
	PINSEL0 = 0x20000000;			/*引脚选中EINT1功能*/
	PINSEL1 = 0x00000001;			/*引脚选中EINT0功能*/
	/*以下为中断控制部分*/		
	VICIntSelect=0;					/*全部中断设置为IRQ,若某位为1是FIQ*/
	VICIntEnable=0x0000C000; 		/*使能EINT1、0,EINT1为第15位,0为14位*/
	VICVectCntl0=0x2E;              /*EINT0最高优先级*/
	VICVectAddr0=(int)Eint0_ISR;    /*设置EINT0向量地址*/
	VICVectCntl1=0x2F;				/*0xF,15号中断*/
	VICVectAddr1=(int)Eint1_ISR;	/*设置中断服务子程序*/
	EXTINT=0x07;	
	  while (1)  {					/*无中断时,两灯一起缓慢闪烁*/
	  	IO0CLR = LED1|LED0;
		delay40();
	  	IO0SET = LED1|LED0;
		delay40();
	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -