实验原理
ARM的P0.25接一个LED,引脚设置时连接EINT1功能,按钮触发中断。中断服务程序另LED快速闪烁。
Proteus仿真电路图
image.png
C语言源程序
#include <LPC21XX.H>
  • #define LEDCON 0x02000000/*LED接在P0.25上*/
  • typedef unsigned int uint32;
  • void IRQ_Eint1(void) __attribute__ ((interrupt));/*声明某函数为中断服务子程序的方法*/
  • uint32 times = 100;/*循环次数默认为100*/
  • void IRQ_Eint1(void){
  •   times = 5;
  •   while((EXTINT&0x02)!=0){
  •                 EXTINT=0x02;                   //清除EINT1中断标志
  •   }
  •   VICVectAddr=0;
  • }
  • void delay100(void)  {                        
  •   unsigned volatile long i,j;
  •   for(i=0;i<10000;i++)
  •   for(j=0;j<times;j++)
  •   ;
  •   if(times > 100){
  •                 times--;
  •   }else if(times <100){
  •                 times++;
  •   }
  • }
  • int  main(void)
  •               {
  •               IO0DIR = LEDCON;
  •               PINSEL0 = 0x20000000;/*引脚选中EINT1功能*/
  •               PINSEL1 = 0x00000000;
  • /*以下为中断控制部分*/                           
  •               VICIntSelect=0;/*全部中断设置为IRQ,若某位为1是FIQ*/
  •               VICIntEnable=0x00008000;/*使能EINT1,EINT为第15位*/
  •               VICVectCntl1=0x2F;/*0xF,15号中断*/
  •               VICVectAddr1=(int)IRQ_Eint1;/*设置中断服务子程序*/
  •               EXTINT=0x07;              
  •                 while (1)  {
  •                               IO0CLR = LEDCON;
  •                             delay100();
  •                               IO0SET = LEDCON;
  •                             delay100();
  •                 }
  • }
  • 复制代码