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

📄 main.c

📁 philips LPC2103 ARM EINT0 EINT3的向量中断试验程序
💻 C
字号:

/*********************************************************************************************************
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by:			weibaoquan
** Created date:		2009-4-26
** Version:				1.0
** Descriptions:		 P0.16低电平触发外部中断0   P0.15低电平触发外部中断2

*********************************************************************************************************/
#include "config.h"

#define   LED    0x03 << 17


#define  LED0    (0X0F<<17) 
  
#define  LED3    (0x01<<19) 
#define  LED4    (0x01<<20) 

void DelayNS (uint32 uiDly)
{
    uint32 i;
    
    for (; uiDly > 0; uiDly--)
    {
        for(i = 0; i < 50000; i++);
    }
}

/*********************************************************************************************************
** Function name:       Eint0IRQ
** Descriptions:        外部中断0服务程序
** input parameters:    无
** ouput parameters:    无
** Returned value:      无
*********************************************************************************************************/
void __irq Eint0IRQ(void)
{                                                                       /*  进入中断取反LED             */
     if ((IO0PIN & (1 << 17)) == 0) {                                        
        IO0SET =1 << 17;                                               /*  熄灭发光二极管              */
    } 
    else {
        IO0CLR =1 << 17;                                               /*  点亮发光二极管              */
    }
    
    while((IO0PIN & (1 <<16)) == 0);                                   /*  等待按键松开                */
    
    EXTINT =0x01;                                                      /*  清中断标志                  */
    VICVectAddr = 0x00;                                                 /*  通知VIC中断处理结束         */
}


/*********************************************************************************************************
** Function name:       Eint0IRQ
** Descriptions:        外部中断0服务程序
** input parameters:    无
** ouput parameters:    无
** Returned value:      无
*********************************************************************************************************/
 void __irq Eint2IRQ(void)
 {                                                                       
    if ((IO0PIN & (1 << 18)) == 0)
     {                                        
       IO0SET = 1 << 18;                                              
   } 
    else {
        IO0CLR =1 << 18;                                              
    }
    
    while((IO0PIN & (1 << 16)) == 0);                                   
    
    EXTINT =0x04;                                                      
   VICVectAddr = 0x00;                                                 
} 
 



/*********************************************************************************************************
** Function name:       main
** Descriptions:        P0.16  P0.15低电平触发外部中断主函数
** input parameters:    无
** ouput parameters:    无
** Returned value:      无
*********************************************************************************************************/
int main (void)
{
  
    PINSEL1 = PINSEL1 & (~(0xFF << 2));                             /*P0.17,P0.18, P0.20,P0.19 设为GPIO*/                         
    IO0DIR  = LED0;                                                   /* P0.17,P0.18,P0.20,P0.19 设为设为输出口PIO*/                                                                     /*  进入中断取反LED             */

  
  
    PINSEL1 = PINSEL1 & (~0x03); 
    PINSEL1 = PINSEL1 | 0x01;                                           /*  设置P0.16为外部中断0管脚    */
    PINSEL0 = PINSEL0 & (~0xC0000000);                                      /*  设置P0.15为外部中断2管脚    */
    PINSEL0 = PINSEL0 | 0x40000000;
    
    
    
    IO0CLR  = LED;                                                      /* P0.17.p0.18 设置输出为高电平 */
    
     IRQEnable();                                                        /*  IRQ中断使能                 */
     EXTMODE  = 0x00;                                                    /*  设置外部中断为低电平触发    */
     EXTPOLAR = 0x00;                                                     /*  设置外部中断下降延触发      */
     
      
     VICIntSelect = 0x00;                                                  /*  设置所有的中断为IRQ中断  */                                                                               
   
   
  
                                             
    VICVectCntl0 = 0x20 | 14;                                        /*  分配外部中断0到向量中断0     */                                                                
    VICVectAddr0 = (uint32)Eint0IRQ;                                  /*  设置中断服务程序地址      */
    
    
     VICVectCntl1 = 0x20 | 16;                                         /*  分配外部中断2到向量中断1     */
     VICVectAddr1 = (uint32)Eint2IRQ;                                   /*  设置中断服务程序地址      */
     
     EXTINT = 0x05;                                                     /*  清EINT0 EINT2中断标志    */
     VICIntEnable = (1 << 14)|(1<<16);                                   /*  使能EINT0 EINT2中断   */   
                                                          

         
         while(1)
      {
        IO0SET = LED4;                                                 
       DelayNS(50);                                                   
        IO0CLR = LED4;            /* 点亮LED1 */                                      
      DelayNS(50); 
        IO0SET = LED3;                                                 
     DelayNS(50);                                                   
        IO0CLR = LED3;              /* 点亮LED2 */                                       
       DelayNS(50); 
      
    }                                                    
    
    while(1);
    return 0;
}
/*********************************************************************************************************
  END FILE
********************************************************************************************************/

⌨️ 快捷键说明

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