小生我想做一个定时中断来点灯与关闭LED 指示灯,碰到问题,希望各位大侠鼎力相助,不胜感谢!
源程序如下:
#include "LPC23xx.H" /* LPC23xx/24xx definitions */
#include "type.h"
#include "target.h"
#include "irq.h"
#include "timer.h"
#define LED 1<<7
void __irq timer0_ISR (void);
INT8U timer0Times = 0;
void timer0Init (void)
{
T1MR0 = 119999;/*匹配寄存器,120000-1,12000000为1秒*/
T1MCR = 0x03;/*产生中断,重置TC*/
T1TCR = 0x01;/*使能定时计数器0*/
VICIntSelect = 0x00000000;
VICIntEnable = 0x00000030;/*开定时计数器1中断*/
// VICIntEnable = 0x00000020;/*开定时计数器1中断*/
VICVectAddr1 = (unsigned long)timer0_ISR;
VICVectCntl1 = 0x20 | 5;/*定时器计数器1为5号中断*/
}
void timer0_ISR (void) __irq
{
uint32 i;
timer0Times++;
if(timer0Times == 10)
{
i=IOSET0; //读出当前LED2控制值
if((i&LED)==0)
{
IOSET0=LED;
}
else
{
IOCLR0=LED;
}
timer0Times = 0;
}
T1IR = 1;/*清除定时器0中断*/
VICVectAddr = 0;
}
/*************************************************************
**
**
**main
**
**
**
*************************************************************/
int main(void)
{
timer0Init();
IODIR0=0x00000080;
T1TCR = 0x00;
// IOSET0 = LED;
IOCLR0 = LED;
return 0;
} |