/****************************************************************************
* 名称:main.c
* 功能:通过外部中断0、外部中断1和外部中断2实现加减计数,并输出数码管显示
****************************************************************************/
#include "config.h"
#define CON 0xff
int i = 0x12345678;
uint8 temp=0x00;
typedef void (*CPU_FNCT_VOID)(void); /* See Note #2a. */
/****************************************************************************
* 名称:eint0()
* 功能:外部中断0处理函数,实现加计数
****************************************************************************/
void eint0(void)
{
temp++;
while(EXTINT&(1<<0))
EXTINT=1<<0;
IO0SET=CON;
IO0CLR=temp;
VICVectAddr=0;
}
/****************************************************************************
* 名称:eint1()
* 功能:外部中断1处理函数,实现减计数
****************************************************************************/
void eint1(void)
{
temp--;
while(EXTINT&(1<<1))
EXTINT=1<<1;
IO0SET=CON;
IO0CLR=temp;
VICVectAddr=0;
}
/****************************************************************************
* 名称:eint2()
* 功能:外部中断2处理函数,清零
****************************************************************************/
void eint2(void)
{
temp=0;
while(EXTINT&(1<<2))
EXTINT=1<<2;
IO0SET=CON;
IO0CLR=temp;
VICVectAddr=0;
}
void IRQ_Exception(void)
{
CPU_FNCT_VOID pfnct;
pfnct = (CPU_FNCT_VOID)VICVectAddr; //返回最高优先级向量地址
if (pfnct != (CPU_FNCT_VOID)0) { /* Make sure we don't have a NULL pointer */
(*pfnct)(); //这句能关联到中断
}
}
delay()
{;}
/****************************************************************************
* 名称:main()
* 功能:初始化外部中断0,外部中断1及I/O连接
****************************************************************************/
int main(void)
{
PINSEL0=0xA0000000; //p0.15/p0.14 as int1 int2
PINSEL1=0x00000001; //p0.16 as int0
IO0DIR=CON; // p0.0-p0.7 as gpio out
IO0SET=CON; //p0.0-p0.7 output 0b11111111
VICIntSelect=0; //irq
VICIntEnable=0x0001c000; //...011100 ... int0-int2 enable
VICVectCntl0=0x0000002e; //14 int0
VICVectCntl1=0x0000002f; //15 int1
VICVectCntl2=0x00000030; //16 int2
//regist int0-int2
VICVectAddr0=(uint32)(eint0);
VICVectAddr1=(uint32 )(eint1);
VICVectAddr2=(uint32)(eint2);
EXTINT=0x07; //clear int flg
delay();
while(1);
}