赞助论坛
  • 4231阅读
  • 0回复

ARM菜鸟外部中断学习笔记 [复制链接]

楼层直达
发帖
132
精华
1
金币
110
威望
5
贡献
2
好评
3
注册
2008-06-06
楼主    大头呆脑 发表于: 2008-06-16 15:00:30 
*----------------------------------------------------------------------
        ARM菜鸟外部中断学习笔记
[email]HotPower@126.com[/email] 2005.7.21 与西安大雁塔村队部
-----------------------------------------------------------------------*/
/***********************************************************************/
/* This file is part of the CA ARM C Compiler package           */
/* Copyright KEIL ELEKTRONIK GmbH 2002 - 2004                 */
/***********************************************************************/
/*                                               */
/* MAIN.C: Demonstration of various interrupt functions         */
/*                                               */
/***********************************************************************/


#include <LPC21xx.H>   // Philips Peripheral Registers
#include "LPC21xxDEF.H"   //ARM菜鸟HotPower创建定义文件
/*
* software interrupt function accept parameters and run in
* supervisor mode (interrupt protected).
*/
int myfunc1 (int i1, long i2) __swi (8) {
return (i1 / i2);
}

int myfunc2 (int i1) __swi (9) {
return (i1<<4);
}


/*
* standard interrupt function saves only R0 - R12 and returns with
*/
void DefaultIRQ (void) __irq {
unsigned int temp;
temp = VICIRQStatus;
IOPIN1 ^= (1 << P1_15);   //取反P1.15
}

void EINT0IRQ (void) __irq {
unsigned int temp;
temp = VICIRQStatus;
IOPIN1 ^= (1 << P1_16);   //取反P1.16
EXTINT = (1 << EINT0);   //清除INT0中断标志
VICVectAddr = 0;
}

void EINT1IRQ (void) __irq {
unsigned int temp;
temp = VICIRQStatus;
IOPIN1 ^= (1 << P1_14);   //取反P1.14
EXTINT = (1 << EINT1);   //清除INT1中断标志
VICVectAddr = 0;
}

/*
* fast interrupt function saves only R0 - R7 and returns with
*/
void FIQ_Handler (void)   __fiq {
//IOSET1 = 0x00010000;     // Set pin P1.16
// IOSET1 = (1 << P1_15);   // Set pin P1.15
IOPIN1 ^= (1 << P1_15);   //取反P1.15
//EXTINT = 0x00000002;     // Clear the peripheral interrupt flag
EXTINT = (1 << EINT2);   //清除INT2中断标志
}

/*
* task functions have no register save/restore and no return.
*/
void tsk (void) __task {
while (1);
}



/*
* Sample 'main' function
*/
int res;

void main (void) {
// IODIR1       = 0x00FF0000;     // Set the LED pins as outputs
IODIR1       = (1 << P1_23) | (1 << P1_22) | (1 << P1_21) | (1 << P1_20)
            |(1 << P1_19) | (1 << P1_18) | (1 << P1_17) | (1 << P1_16);//设置LED输出方式
// PINSEL0       = 0x20000000;   // Enable the EXTINT1 interrupt
PINSEL0       |= (P0_14_EINT1 << P0_14_PINSEL);//选择P0.14为INT1外部中断引脚

EXTMODE     |= (1 << EXTMODE1);//设置INT1为边沿触发,低电平有效

PINSEL1       |= (P0_16_EINT0 << P0_16_PINSEL);//选择P0.16为INT0外部中断引脚

EXTMODE     |= (1 << EXTMODE0);//设置INT1为边沿触发,低电平有效

PINSEL0       |= (P0_15_EINT2 << P0_15_PINSEL);//选择P0.15为INT2外部中断引脚

EXTMODE     |= (1 << EXTMODE2);//设置INT2为边沿触发,低电平有效

// VICVectAddr15 = (unsigned long) DefaultIRQ;

// VICIntSelect   = 0x00008000;     // Enable a Vic Channel as FIQ
VICIntSelect   = (1 << VICIntSel_EINT2);     // Enable a Vic Channel as FIQ
// VICIntSelect   = 0;     // Enable a Vic Channel as FIQ

VICVectCntl0   = VICIntSel_Enable | VICIntSel_EINT0;
VICVectAddr0   = (unsigned long *) &EINT0IRQ;//取INT0中断服务地址


VICVectCntl1   = VICIntSel_Enable | VICIntSel_EINT1;
VICVectAddr1   = (unsigned long *) &EINT1IRQ;//取INT1中断服务地址


// VICIntEnable   = 0x00008000;     // Set Default interrupt vector
VICIntEnable   = (1 << VICIntSel_EINT0)
          | (1 << VICIntSel_EINT1)
          | (1 << VICIntSel_EINT2);//使能中断

EXTINT = (1 << EINT0) | (1 << EINT1) | (1 << EINT2);   //清除INT中断标志

// VICDefVectAddr = (unsigned long *) &DefaultIRQ;

// VICSoftInt   = (1 << VICIntSel_EINT1);

res = myfunc1 (10, 2);       // call SWI functions
res += myfunc2 (res);


while (1);               // endless loop
}