#include <intrinsics.h>
#include <stdio.h>
#include <NXP/iolpc2132.h>
int flag = 0;
#define IRQV 0x18
#pragma vector=IRQV
__irq __arm void irq_handler (void)
{
void (*interrupt_)();
unsigned int vector;
vector = VICVectAddr;
interrupt_ = (void(*)())vector;
if(interrupt_ != NULL)
{
interrupt_();
}
else
{
VICVectAddr = 0;
}
}
void IRQ_Timer0 (void)
{
T0IR = 0x01; /* 清除中断标志 */
if (flag)
{
IO0SET_bit.P0_12 = 1;
flag = 0;
}
else
{
IO0CLR_bit.P0_12 = 1;
flag = 1;
}
VICVectAddr = 0x00; /* 通知VIC中断处理结束 */
}
void VicInit(void)
{
VICIntSelect = 0x0; /* 所有中断通道设置为IRQ中断*/
VICIntEnClear = 0xFFFFFFFF;
VICSoftIntClear = 0xFFFFFFFF;
VICProtection = 0;
VICVectAddr = 0;
VICDefVectAddr = 0;//VICVectCntl1
VICVectAddr0 = VICVectAddr1 = VICVectAddr2 = VICVectAddr3 =\
VICVectAddr4 = VICVectAddr5 = VICVectAddr6 = VICVectAddr7 =\
VICVectAddr8 = VICVectAddr9 = VICVectAddr10 = VICVectAddr11 =\
VICVectAddr12 = VICVectAddr13 = VICVectAddr14 = VICVectAddr15 = 0;
VICVectCntl0 = VICVectCntl1 = VICVectCntl2 = VICVectCntl3 =\
VICVectCntl4 = VICVectCntl5 = VICVectCntl6 = VICVectCntl7 =\
VICVectCntl8 = VICVectCntl9 = VICVectCntl10 = VICVectCntl11 =\
VICVectCntl12 = VICVectCntl13 = VICVectCntl14 = VICVectCntl15 = 0;
}
void Gpio_Init(void)
{
PINSEL0 = PINSEL0&0xF0FFFFFF; //P0.12,P0.13 设置为GPIO,不影响其他引脚的功能
IO0DIR_bit.P0_12 = 1; //设置P0.12方向
IO0DIR_bit.P0_13 = 1; //设置P0.13方向
IO0SET_bit.P0_12 = 1;
IO0SET_bit.P0_13 = 1;
}
void Timer0_Init(void)
{
T0TCR = 2;
T0CTCR = 0;
T0PR = 0;
T0MR0 = Fpclk;
T0MCR = 3;
T0EMR = 0;
VICIntSelect = 0x0;
VICVectAddr0 = (unsigned int)IRQ_Timer0;
VICVectCntl0 = 0x20 | 0x04;
VICIntEnable = 0x10;
T0TCR = 1;
}
void main()
{
MEMMAP_bit.MAP = 2;
__disable_interrupt();
VicInit();
Gpio_Init();
Timer0_Init();
__enable_interrupt();
while(1)
{
;
}
}
(842267939) 17:49:11
|