|
小弟刚学DSP,弄定时器时有些问题希望各位给解释一下;谢谢啦
注释有很多问号的是我不明白的。
代码:
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
// Prototype statements for functions found within this file.
interrupt void cpu_timer0_isr(void);
#define LEDS *(int *)0xc0000 //定义LED接口
int i=0,nCount;
unsigned int uLBD;
void main(void)
{
InitSysCtrl();//初始化cpu
DINT;//关中断
InitPieCtrl();//初始化pie寄存器
IER = 0x0000;//禁止所有的中断
IFR = 0x0000;//中断标志清零
InitPieVectTable();//初始化pie中断向量表
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;//指定中断服务子程序
EDIS; // This is needed to disable write to EALLOW protected registers
CpuTimer0.RegsAddr = &CpuTimer0Regs;//?????????????????????
// Initialize timer period to maximum:
CpuTimer0Regs.PRD.all = 0xffff;
CpuTimer0Regs.TPRH.all = 0;
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
CpuTimer0Regs.TPR.all = 0;
CpuTimer0Regs.TIM.all = 0;
// Make sure timer is stopped:
CpuTimer0Regs.TCR.bit.TSS = 1;//停止定时器
CpuTimer0Regs.TCR.bit.FREE = 1;//FREE : SOFT=1 : 1 定时器自由运行
CpuTimer0Regs.TCR.bit.SOFT = 1;
// Reload all counter register with period value:
CpuTimer0Regs.TCR.bit.TRB = 1;//TIMH:TIM寄存器重新装载PRDH:PRD中的周期值
CpuTimer0Regs.TCR.bit.TIE = 1;//定时器中断使能
// Reset interrupt counters:
CpuTimer0.InterruptCount = 0;//????????????????????????????
StartCpuTimer0();//启动定时器0
// Enable CPU INT1 which is connected to CPU-Timer 0:
IER |= M_INT1;//使能中断组1
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //在PIE中使能Timer0中断
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM 使能全局中断
ERTM; // Enable Global realtime interrupt DBGM
while ( 1 )
{
}
}
interrupt void cpu_timer0_isr(void)
{
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //?????????????????????????????????
CpuTimer0Regs.TCR.bit.TIF = 1;//写1清除该标志位
CpuTimer0Regs.TCR.bit.TRB = 1;//TIMH:TIM寄存器重新装载PRDH:PRD中的周期值
if ( nCount==0 )
{
LEDS=uLBD;
uLBD++;
uLBD%=16;
}
nCount++;
nCount%=194;
}
//===========================================================================
// No more.
//========================================
补充:是怎样计算出定时时间的?? |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|