各位大侠:小弟将按键的外部中断做好后,在研究内部中断。其实内部中断相对来说更为简单,但是定时器中断的问题,我始终没有解决。我要求“每隔2秒蜂鸣器响一次,持续时间为0.5秒,并伴随着LED亮”。通过AXD查看系统寄存器的配置,都没有问题,这里用的的MMU.c文件是做按键中断时修改好的,也没问题,就是没实验结果。我将源代码奉上,请各位仁兄指点!
//中断方式实现精确延时
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
//================================
void __irq Timer4_ISR(void)
{
static int count;
count++;
rSRCPND = rSRCPND|(0x1<<14);
rINTPND = rINTPND|(0x1<<14);
//每隔2秒蜂鸣器响一次,持续时间为0.5秒,并伴随着LED亮
if (count % 4 ==0)
rGPBDAT = ~0x1e0; //蜂鸣器响,LED亮
else if (count % 4 ==1)
rGPBDAT = 0x1e0; //蜂鸣器不响,LED灭
}
int Main(int argc, char **argv)
{
U32 mpll_val=0;
mpll_val = (92<<12)|(1<<4)|(1);
//init FCLK=400M, so change MPLL first
ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);
ChangeClockDivider(14, 12);
MMU_Init();
Port_Init();
rGPBCON = 0x155555;
rGPBUP = 0x7ff;
rGPBDAT = 0x1e0;//蜂鸣器不响,LED灭
rSRCPND = rSRCPND|(0x1<<14);
rINTPND = rINTPND|(0x1<<14);
rINTMSK = ~(0x1<<14); //打开定时器4中断
rTCFG0 &= 0xFF00FF;
rTCFG0 |= 0xf900; // Timer4的prescaler=249
rTCFG1 &= ~0xF0000;
rTCFG1 |= 0x20000; //Timer的divider=8,则设置定时器4的时钟频率为25kHz
rTCNTB4 = 12500; //让定时器4每隔0.5秒中断一次
rTCON &= ~0xF00000;
rTCON |= 0x700000;
rTCON &= ~0x200000;//启动定时器
pISR_TIMER4=(U32)Timer4_ISR;
while(1)
{
;
}
return 0;
}