加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSSRSS-巴斯仪表网
您当前的位置:首页 > 电子发烧 > 单片机学习

ARM菜鸟外部中断学习笔记

时间:2013-11-23  来源:123485.com  作者:9stone

*----------------------------------------------------------------------
              ARM菜鸟外部中断学习笔记
HotPower@126.com  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
}

 

LPC21XXDEF.H
/*----------------------------------------------------
文   件   名:  LPC21XXDEF.H
创   建   人:  ARM菜鸟HotPower@126.com
最近修改日期:  2005.7.21
创 建 地 点 : 西安大雁塔村队部
------------------------------------------------------*/


#ifndef __LPC21xxDEF_H
#define __LPC21xxDEF_H

#define BV(val) (1 << val)

#define VICIntSel_Watchdog  0
#define VICIntSel_VicInt1   1
#define VICIntSel_VicInt2   2
#define VICIntSel_VicInt3   3
#define VICIntSel_Time0     4
#define VICIntSel_Time1     5
#define VICIntSel_UART0     6
#define VICIntSel_UART1     7
#define VICIntSel_PWM       8
#define VICIntSel_I2C0      9
#define VICIntSel_SPI0     10
#define VICIntSel_SSP      11
#define VICIntSel_PLLLock  12
#define VICIntSel_RTC      13
#define VICIntSel_EINT0    14
#define VICIntSel_EINT1    15
#define VICIntSel_EINT2    16
#define VICIntSel_EINT3    17
#define VICIntSel_ADC0     18
#define VICIntSel_I2C1     19
#define VICIntSel_BOD      20
#define VICIntSel_ADC1     21
#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_Enable   32

//
#define P0_0  0//P0.0
#define P0_1  1//P0.1
#define P0_2  2//P0.2
#define P0_3  3//P0.3
#define P0_4  4//P0.4
#define P0_5  5//P0.5
#define P0_6  6//P0.6
#define P0_7  7//P0.7
#define P0_8  8//P0.8
#define P0_9  9//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_0  0//P1.0
#define P1_1  1//P1.1
#define P1_2  2//P1.2
#define P1_3  3//P1.3
#define P1_4  4//P1.4
#define P1_5  5//P1.5
#define P1_6  6//P1.6
#define P1_7  7//P1.7
#define P1_8  8//P1.8
#define P1_9  9//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_GPIO    0
  #define P0_0_TXD0  1
  #define P0_0_PWM1  2
#define P0_0_PINSEL 2 * P0_0

#define P0_1_GPIO 0
  #define P0_1_RXD0  1
  #define P0_1_PWM1  2
  #define P0_1_EINT0 3
#define P0_1_PINSEL 2 * P0_1

#define P0_2_GPIO    0
  #define P0_2_SCL0  1
#define P0_2_PINSEL 2 * P0_2

#define P0_3_GPIO    0
  #define P0_3_SDA0  1
  #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_CD    1//LPC2138
  #define P0_14_EINT1 2
  #define P0_14_SDA1  3
#define P0_14_PINSEL 2 * P0_14

#define P0_15_GPIO 0
  #define P0_15_RI    1//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


分享到:
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
栏目导航->单片机学习
  • 电子应用基础
  • 电源技术
  • 无线传输技术
  • 信号处理
  • PCB设计
  • EDA技术
  • 单片机学习
  • 电子工具设备
  • 技术文章
  • 精彩拆解欣赏
  • 推荐资讯
    使用普通运放的仪表放大器
    使用普通运放的仪表放
    3V与5V混合系统中逻辑器接口问题
    3V与5V混合系统中逻辑
    数字PID控制及其改进算法的应用
    数字PID控制及其改进
    恶劣环境下的高性价比AD信号处理数据采集系统
    恶劣环境下的高性价比
    栏目更新
    栏目热门