*----------------------------------------------------------------------
ARM菜鸟外部中断学习笔记
HotPower@126.com2005.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
#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
}
LPC21XXDEF.H
/*----------------------------------------------------
文件名:LPC21XXDEF.H
创建人:ARM菜鸟HotPower@126.com
最近修改日期:2005.7.21
创 建 地 点 : 西安大雁塔村队部
------------------------------------------------------*/
#ifndef __LPC21xxDEF_H
#define __LPC21xxDEF_H
#define BV(val) (1 << val)
#define VICIntSel_Watchdog0
#define VICIntSel_VicInt11
#define VICIntSel_VicInt22
#define VICIntSel_VicInt33
#define VICIntSel_Time04
#define VICIntSel_Time15
#define VICIntSel_UART06
#define VICIntSel_UART17
#define VICIntSel_PWM8
#define VICIntSel_I2C09
#define VICIntSel_SPI010
#define VICIntSel_SSP11
#define VICIntSel_PLLLock12
#define VICIntSel_RTC13
#define VICIntSel_EINT014
#define VICIntSel_EINT115
#define VICIntSel_EINT216
#define VICIntSel_EINT317
#define VICIntSel_ADC018
#define VICIntSel_I2C119
#define VICIntSel_BOD20
#define VICIntSel_ADC121
#define VICIntSel_VicInt22 22
#define VICIntSel_VicInt23 23
#define VICIntSel_VicInt24 24
#define VICIntSel_VicInt25 25
#define VICIntSel_VicInt26 26
#define VICIntSel_VicInt27 27
#define VICIntSel_VicInt28 28
#define VICIntSel_VicInt29 29
#define VICIntSel_VicInt30 30
#define VICIntSel_VicInt31 31
#define VICIntSel_Enable32
//
#define P0_00//P0.0
#define P0_11//P0.1
#define P0_22//P0.2
#define P0_33//P0.3
#define P0_44//P0.4
#define P0_55//P0.5
#define P0_66//P0.6
#define P0_77//P0.7
#define P0_88//P0.8
#define P0_99//P0.9
#define P0_10 10//P0.10
#define P0_11 11//P0.11
#define P0_12 12//P0.12
#define P0_13 13//P0.13
#define P0_14 14//P0.14
#define P0_15 15//P0.15
#define P0_16 16//P0.16
#define P0_17 17//P0.17
#define P0_18 18//P0.18
#define P0_19 19//P0.19
#define P0_20 20//P0.20
#define P0_21 21//P0.21
#define P0_22 22//P0.22
#define P0_23 23//P0.23
#define P0_24 24//P0.24
#define P0_25 25//P0.25
#define P0_26 26//P0.26
#define P0_27 27//P0.27
#define P0_28 28//P0.28
#define P0_29 29//P0.29
#define P0_30 30//P0.30
#define P0_31 31//P0.31
//
#define P1_00//P1.0
#define P1_11//P1.1
#define P1_22//P1.2
#define P1_33//P1.3
#define P1_44//P1.4
#define P1_55//P1.5
#define P1_66//P1.6
#define P1_77//P1.7
#define P1_88//P1.8
#define P1_99//P1.9
#define P1_10 10//P1.10
#define P1_11 11//P1.11
#define P1_12 12//P1.12
#define P1_13 13//P1.13
#define P1_14 14//P1.14
#define P1_15 15//P1.15
#define P1_16 16//P1.16
#define P1_17 17//P1.17
#define P1_18 18//P1.18
#define P1_19 19//P1.19
#define P1_20 20//P1.20
#define P1_21 21//P1.21
#define P1_22 22//P1.22
#define P1_23 23//P1.23
#define P1_24 24//P1.24
#define P1_25 25//P1.25
#define P1_26 26//P1.26
#define P1_27 27//P1.27
#define P1_28 28//P1.28
#define P1_29 29//P1.29
#define P1_30 30//P1.30
#define P1_31 31//P1.31
#define EXTMODE0 0//EXTMODE.0
#define EXTMODE1 1//EXTMODE.1
#define EXTMODE2 2//EXTMODE.2
#define EXTMODE3 3//EXTMODE.3
#define EINT0 0//EXTINT.0
#define EINT1 1//EXTINT.1
#define EINT2 2//EXTINT.2
#define EINT3 3//EXTINT.3
//
#define P0_0_GPIO0
#define P0_0_TXD01
#define P0_0_PWM12
#define P0_0_PINSEL 2 * P0_0
#define P0_1_GPIO 0
#define P0_1_RXD01
#define P0_1_PWM12
#define P0_1_EINT0 3
#define P0_1_PINSEL 2 * P0_1
#define P0_2_GPIO0
#define P0_2_SCL01
#define P0_2_PINSEL 2 * P0_2
#define P0_3_GPIO0
#define P0_3_SDA01
#define P0_3_EINT1 3
#define P0_3_PINSEL 2 * P0_3
#define P0_4_GPIO 0
#define P0_4_PINSEL 2 * P0_4
#define P0_5_GPIO 0
#define P0_5_PINSEL 2 * P0_5
#define P0_6_GPIO 0
#define P0_6_PINSEL 2 * P0_6
#define P0_7_GPIO 0
#define P0_7_PINSEL 2 * P0_7
#define P0_8_GPIO 0
#define P0_8_PINSEL 2 * P0_8
#define P0_9_GPIO 0
#define P0_9_PINSEL 2 * P0_9
#define P0_10_GPIO 0
#define P0_10_PINSEL 2 * P0_10
#define P0_11_GPIO 0
#define P0_11_PINSEL 2 * P0_11
#define P0_12_GPIO 0
#define P0_12_PINSEL 2 * P0_12
#define P0_13_GPIO 0
#define P0_13_PINSEL 2 * P0_13
#define P0_14_GPIO 0
#define P0_14_CD1//LPC2138
#define P0_14_EINT1 2
#define P0_14_SDA13
#define P0_14_PINSEL 2 * P0_14
#define P0_15_GPIO 0
#define P0_15_RI1//LPC2138
#define P0_15_EINT2 2
#define P0_15_PINSEL 2 * P0_15
#define P0_16_GPIO 0
#define P0_16_EINT0 1
#define P0_16_PINSEL 2 * P0_0
#define P0_17_GPIO 0
#define P0_17_PINSEL 2 * P0_1
#define P0_18_GPIO 0
#define P0_18_PINSEL 2 * P0_2
#define P0_19_GPIO 0
#define P0_19_PINSEL 2 * P0_3
#define P0_20_GPIO 0
#define P0_20_PINSEL 2 * P0_4
#define P0_21_GPIO 0
#define P0_21_PINSEL 2 * P0_5
#define P0_22_GPIO 0
#define P0_22_PINSEL 2 * P0_6
#define P0_23_GPIO 0
#define P0_23_PINSEL 2 * P0_7
#define P0_24_GPIO 0
#define P0_24_PINSEL 2 * P0_8
#define P0_25_GPIO 0
#define P0_25_PINSEL 2 * P0_9
#define P0_26_GPIO 0
#define P0_26_PINSEL 2 * P0_10
#define P0_27_GPIO 0
#define P0_27_PINSEL 2 * P0_11
#define P0_28_GPIO 0
#define P0_28_PINSEL 2 * P0_12
#define P0_29_GPIO 0
#define P0_29_PINSEL 2 * P0_13
#define P0_30_GPIO 0
#define P0_30_PINSEL 2 * P0_14
#define P0_31_GPIO 0
#define P0_31_PINSEL 2 * P0_15
#endif// __LPC21xxDEF_H